Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8337089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:11:28+00:00 2026-06-09T04:11:28+00:00

Can I add values to an instance of an object after I have used

  • 0

Can I add values to an instance of an object after I have used the constructor?

For instance I have this code. I have to make a list of objects which require a number n, and the time (which are recieved as arguments). The problem is that the time can be anywhere so I can’t use it in a constructor.

 public List<IAction> Dispatch(string[] arg)
   {
       int time;
       int i = 0;
       int j = 0;
       List<IAction> t = new List<IAction>(10);
       do
       {
           if (int.Parse(arg[j]) >= 0 && int.Parse(arg[j]) <= 20)
           {
               t.Add(new ComputeParam(int.Parse(arg[j]))); 

               i++;
               j++;

           }
           else
           {
               if (arg[i][0] == '/' && arg[i][1] == 't')
               {
                   Options opt = new Options();
                   j++;

                   time=opt.Option(arg[i]); //sets the time 0,1000 or 2000


               }


           }
       } while (i != arg.Length);
       return t;

}

After finishing making the list can I do something like:

for(int i=0; i<=t.Count; i++)
{
*add time to t[i]*
}

How do I do this?

Thanks in advance!

Edit :

here is the ComputeParam class

public class ComputeParam : IAction
{
    int n;
    int time;
    public ComputeParam()
    {
    }
    public ComputeParam(int n)
    {
        this.n = n;
    }

    public void run()
    {


        Factorial Fact = new Factorial();
        Fact.Progression += new Factorial.ProgressEventHandler(Progress);
        Console.WriteLine("                                        ");
        Console.Write("\n" + "Partial results : ");
        Console.CursorLeft = 35;
        Console.Write("Progress : ");
        int Result = Fact.CalculateFactorial(n, time);
        Console.WriteLine(" ");
        Console.WriteLine("The factorial of " + n + " is : " + Result);

        Console.WriteLine("Press Enter to continue...");
        Console.CursorTop -= 2;
        Console.CursorLeft = 0;

        Console.ReadLine();
    }

    public void Progress(ProgressEventArgs e)
    {
        int result = e.getPartialResult;
        int stack_value = e.getValue;
        double max = System.Convert.ToDouble(n);
        System.Convert.ToDouble(stack_value);
        double percent = (stack_value / max) * 100;

        Console.CursorLeft = 18;
        Console.Write(result + " ");
        Console.CursorLeft = 46;
        Console.Write(System.Convert.ToInt32(percent) + "%      ");

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:11:29+00:00Added an answer on June 9, 2026 at 4:11 am

    If the object has a public property, I don’t see why not.
    Edit: Looks like you need to add a public property to your class. Also note, given that there is a public constructor that takes 0 params, you should also add a property for n.

    public class ComputeParam : IAction    
    {    
        int _n;    
        int _time;    
        public ComputeParam()    
        {    
        }    
        public ComputeParam(int n)    
        {    
            this._n = n;    
        }  
        public int Time 
        { 
            get { return this._time; }
            set { this._time = value; }
        }
    
        public int N
        {
            get { return this._n; }
            set { this._n = value; }
        }
    
    
    for(int i = 0; i < t.Count; i++) 
    { 
        ((ComputeParam)t[i]).Time = 6;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with WPF Toolkit Chart Control. I can't add text values
Simple. If I use: public void Add(params int[] values) Then I can use this
I have a Card Object, which have 4 instance variables namely name(NSString), pin(NSString), points(NSNumber),
Can I add multiple values in one key in isolated storage settings? How?
How i can add the multiple values from a datagrid to textbox in C#?
How can one add two long values in Java so that if the result
How can I add all of my array values together in PHP? Is there
How can I add key value pairs to an array? This won't work: public
How can i reset a display:none and add some value here is the code
In my application I have an extended User model called UserProfile. This user can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.