Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple objects in list, C#

Tags:

c#

list

wpf

I'm looking for something similar to List<T>, that would allow me to have multiple T. For example: List<TabItem, DataGrid, int, string, ...> = new List<TabItem, DataGrid, int, string, ...>().

like image 443
anon Avatar asked Jun 07 '10 15:06

anon


People also ask

How do you add multiples in a list?

Using + operator to append multiple lists at once This can be easily done using the plus operator as it does the element addition at the back of the list. Similar logic is extended in the case of multiple lists.

Can a class have multiple objects?

A program may create many objects of the same class. Objects are also called instances, and they can be stored in either a named variable or in an array or collection. Client code is the code that uses these variables to call the methods and access the public properties of the object.

Can you add the same object to a list multiple times?

Therefore, we can insert the same object or reference to a single object as many times as we want.


2 Answers

If you are using .NET 4, you could have a List<Tuple<T1, T2, ...>>

Otherwise, your choice is to implement your own type.

like image 168
Anthony Pegram Avatar answered Sep 28 '22 08:09

Anthony Pegram


Create a class that defines your data structure, and then do

var list = new List<MyClass>();
like image 41
D'Arcy Rittich Avatar answered Sep 28 '22 06:09

D'Arcy Rittich