generic input object example?

I am trying to create a input class object to store different input variables so that I can always pass this input object only as a parameter to number of methods I have.

CalculateSomethingMethod1(MyInputObject myInputobject) {

}

CalculateSomethingMethod2(MyInputObject myInputobject) {

}

I have a lot of calculation methods with a lot of input parameters (4-12) and I am trying to create a generic input class so I can store those input paramenters.

Is there any examples I can look?

I am going to store, objects, string, integer, and double.
dkim18Asked:
Who is Participating?
 
Jaime OlivaresSoftware ArchitectCommented:
There are many options for this. You can pass a array or List of objects (List allows you to dynamically increase the list). So, you can derive your class from that list:

public MyInputObject : List<object>
{
    // some implementation here, if needed
}

then you can use it as:

MyInputObject o = new MyInputObject();
o.Add(5);
o.Add("some string");
o.Add(3.7);

CalculateSomethingMethod1(o);
0
 
Jaime OlivaresSoftware ArchitectCommented:
@dkim18,
I just noticed you have specified both Java and C#. Which is the specific language you are targeting?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.