static void Main(string[] args) { IndexedNames names_2 = new IndexedNames( "Zara", "Riz", "Nuha", "Asif", "Davinder", "Sunil", "Rubic"); IndexedNames names3 = new IndexedNames(); //using the first indexer with int parameter to reverse the order for (int i = 0; i < IndexedNames.size; i++) { names3[i] = names_2[IndexedNames.size - i]; } // What kind of copy does this really do!!? IndexedNames names = names3; //using the first indexer with int parameter to print the list for (int i = 0; i < IndexedNames.size; i++) { Console.WriteLine(i + ": " + names[i]); } //using the second indexer with the string parameter Console.WriteLine("Type which name to find it's index for:"); string name = Console.ReadLine(); Console.WriteLine("Indexed is: " + names[name]); Console.ReadKey(); }
static void Main(string[] args) { var names = new IndexedNames(); names[0] = "hello1"; names[1] = "hello2"; names[2] = "hello3"; names[3] = "hello4"; names[4] = "hello5"; names[5] = "hello6"; names[6] = "hello7"; names[7] = "hello8"; names[8] = "hello9"; names[9] = "hello10"; for (int i = 0; i < 10; i++) { Console.WriteLine(names[i]); } Console.WriteLine(names["hello1"]); Console.WriteLine(names["hello2"]); Console.WriteLine(names["hello3"]); Console.WriteLine(names["hello4"]); Console.WriteLine(names["hello99"]); Console.ReadLine(); }
static void Main(string[] args) { var names = new IndexedNames(); names [0] = "wq"; names[1] = "Hello"; names[2] = "Hello1"; names[3] = "Hello2"; names[4] = "Hello3"; names[5] = "Hello4"; names[6] = "Hello5"; names[7] = "Hello6"; names[8] = "Hello7"; names[9] = "Hello8"; // names[10] = "Hello9"; //names[11] = "Hello10"; //names[12] = "Hello11"; for (int i = 0; i <= 9; i++) { Console.WriteLine(names[i]); } Console.WriteLine(names["Hello"]); Console.WriteLine(names["Hello5"]); Console.WriteLine(names["Hello0"]); Console.ReadLine(); }
static void Main(string[] args) { var names = new IndexedNames(); names[0] = "Hello"; names[1] = ".net"; names[2] = "wo"; names[3] = "are"; names[4] = "learning"; names[5] = "C#"; names[6] = "Indexer"; names[7] = "-"; names[8] = "Indexer"; names[9] = "Syntax"; for (int i = 0; i <= 9; i++) { Console.WriteLine(names[i]); } Console.WriteLine(names["C#"]); Console.WriteLine(names["Syntax"]); Console.WriteLine(names["2015"]); }
static void Main(string[] args) { var names = new IndexedNames(); names[0] = "hello"; names[1] = "zilong"; names[2] = "we"; names[3] = "are"; names[4] = "leaning"; names[5] = "C#"; names[6] = "Indexer"; names[7] = "-"; names[8] = "Indexex"; names[9] = "syntax"; for (int i = 0; i < 10; i++) { Console.WriteLine(names[i]); } Console.WriteLine(names["C#"]); Console.WriteLine(names["syntax"]); Console.WriteLine(names["2016"]); Console.ReadLine(); }