C# Generics List<T>


Generics List<T>

namespace MikeList {  // Generics - List<T> page 312
    class Program  {  // Chapter 12, Written by Mike
        // Compare Ch11Ex02. This is much easier than 
        // deriving a class from CollectionBase and then
        // implement the required methods.
        static void Main(string[] args) {
            List<string> myList = new List<string>();
            string myString = "hello world";
            string myOtherString = "hi world";
            string myThirdString = "a message for you";
            myList.Add(myString);
            myList.Add(myOtherString);
            myList.Add(myThirdString);
            WriteLine($"{myList[0]} \n");  // the first one
            foreach (string myStrg in myList)
                { WriteLine(myStrg); }
            myList.Sort();   WriteLine("\n");
            foreach (string myStrg in myList)
                { WriteLine(myStrg); }
            ReadKey();
        }
    }  // using System.Collections.Generic;
}

Leave a comment

Your email address will not be published. Required fields are marked *