I am searching for a solution to create List<>
of Lists with different data types like
List<List<int>,List<double>,List<string>> list;
or a List<>
with multiple data types like
List<int,double,string> list;
In all seriousness... why?
The code which consumes these structures is going to be confusing and difficult to support. It really, really will.
If you have a custom structure to your data, create a custom object to represent that structure. Something like this:
class MyThing
{
public int Widget { get; set; }
public double Foo { get; set; }
public string Something { get; set; }
}
Use actual meaningful names for your values/types/etc. of course, because that's the entire point of doing this.
Then just have a list of those:
var things = new List<MyThing>();
As your structure continues to change and grow, you build the logic of that structure into the object itself, rather than into all of the consuming code which uses it. The code which uses it then more closely approximates the semantics of the operations it's trying to perform, rather than a dizzying assortment of syntactic operations.
May be you can do like this
public class Helper
{
public object value;
private string Type;
}
then create list
List<Helper> myList=new List<Helper>();
use like this
myList.Add(new Helper {value = 45,Type = "int"});
myList.Add(new Helper {value = 45,Type = "int"});
myList.Add(new Helper {value = "hello",Type = "string"});
and the covert according to Type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With