Multiple objects in a list, C #

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

+5
source share
7 answers

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

Otherwise, your choice is to implement your own type.

+14
source

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

var list = new List<MyClass>();
+7
source

List<MyClass>, MyClass , .

+1

, ArrayList.

, , , .

+1

, List<object>?

-1

, .net 4.0. 3.5 , . . 3 , , . , . .

class Program
{
    static void Main(string[] args)
    {
        object[,] OneObject = new object[1,3]{ {"C Sharp",4,3.5 }};
        List<object> MyList = new List<object>();
        MyList.Add(OneObject);
        object[,] addObject = new object[1,3]{{"Java",1,1.1}};
        MyList.Add(addObject);

        foreach(object SingleObject in MyList)
        {
            object[,] MyObject = (object[,])SingleObject;

            Console.WriteLine("{0},{1},{2}", MyObject[0, 0], MyObject[0, 1], MyObject[0, 2]);
        }  

        Console.Read();
    }
}
-1

, # 4, .

, , ArrayList - .

-1

All Articles