Is there a simple way to have a class with two constructors such as:
public MyClass
{
public MyClass(object obj)
{
}
public MyClass(List<object> obj)
{
}
}
Where instantiating MyClass
by passing in a List<int>
parameter will cause the List<object>
constructor to be used?
It seems this correctly uses the List<object>
constructor:
List<object> l = new List<object>();
l.Add(10);
l.Add(20);
MyClass c = new MyClass(l);
But this goes to the object
constructor instead of the List<object>
constructor:
MyClass c = new MyClass(new List<int> { 10, 20 });
Any idea how to correct this? I'd like to use the List<object>
constructor if any List<>
is passed in.
Thanks!