Use generic list to store your own class : Generic List « Generic « C# / CSharp Tutorial






using System.Collections.Generic;
using System;


class MainClass
{
    public static void Main(string[] args)
    {

        List<MyClass> list = new List<MyClass>();

        list.Add(new MyClass());

        MyClass ass2 = list[0];

        Console.WriteLine("\nFound in list: {0}", ass2);
    }
}
class MyClass {
    
   public override string ToString(){
    
      return "my class";
   }
    
}
Found in list: my class








18.2.Generic List
18.2.1.Use generic list to store your own class
18.2.2.Create Reverse Iterator
18.2.3.Add value to Generic List and display the array list using array indexing
18.2.4.Remove elements from generic List
18.2.5.Use foreach loop to display the generic list
18.2.6.List Capacity and Element Count
18.2.7.Change contents in a generic List using array indexing
18.2.8.Store user-defined Objects in a List collection