static void Main(string[] args) { StringDataStore strStore = new StringDataStore(); strStore[0] = "One"; strStore[1] = "Two"; strStore[2] = "Three"; strStore[3] = "Four"; for (int i = 0; i < 10; i++) { Console.WriteLine(strStore[i]); } Console.WriteLine(strStore["one"]); Console.WriteLine(strStore["tWo"]); Console.WriteLine(strStore["Three"]); Console.WriteLine(strStore["FOUR"]); Console.WriteLine(strStore[0]); String name = "eddie"; Console.WriteLine(name.Equals(String.Empty)); Console.WriteLine(name.EndsWith("ie")); Console.WriteLine(name.Contains('d')); }
static void Main(string[] args) { Console.WriteLine("_1-------------------------------------------------------------"); //Object of StringDataStore can be used like an array to: //1)-add or retrive string data using int indexer. //2)-retrive index data using string indexer. StringDataStore strStore = new StringDataStore(); strStore[0] = "One"; strStore[1] = "Two"; strStore[2] = "Three"; strStore[3] = "Four"; //Using int indexer Console.WriteLine("Return the name of index=0 by int indexer: " + strStore[0]); Console.WriteLine("Return the name of index=1 by int indexer: " + strStore[1]); //Using string indexer Console.WriteLine("Return the index of name=Three by string indexer: " + strStore["Three"]); Console.WriteLine("Return the index of name=FOUR by string indexer: " + strStore["FOUR"]); Console.WriteLine("_2-------------------------------------------------------------"); //Using indexer with linq expression Customer cust1 = new Customer("Mohamed"); cust1.AddOrder(10); cust1.AddOrder(20); cust1.AddOrder(30); //Return all the orders of a specific customer using indexer foreach (Order o in cust1["Mohamed"]) { Console.WriteLine($"The customer {o.CustomerName}, has the following orders: { o.OrderID }"); } //Return the customer name for a specific order using indexer foreach (Order o in cust1.Orders) { Console.WriteLine($"for order number {o.OrderID}, The customer name is: { cust1[o.OrderID] }"); } Console.WriteLine("_3-------------------------------------------------------------"); //Indexers with Multiple Parameters //Set or retrieve player name accoding to its board position using: //1)-multiple parameter indexer. //2)-string indexer. Board board = new Board(); board["A", 4] = new Player("White King"); board["H", 4] = new Player("Black King"); Console.WriteLine("A4 = {0}", board["A", 4]); Console.WriteLine("H4 = {0}", board["H4"]); // A4 = White King // H4 = Black King }
static void Main(string[] args) { StringDataStore strStore = new StringDataStore(); strStore[0] = "One"; strStore[1] = "Two"; strStore[2] = "Three"; strStore[3] = "Four"; Console.WriteLine(strStore[0]); Console.WriteLine(strStore[1]); Console.WriteLine(strStore["Three"]); Console.WriteLine(strStore["Four"]); }
static void Main(string[] args) { StringDataStore strStore = new StringDataStore(); strStore.StoreId = 1000; strStore[0] = "One"; strStore[1] = "Two"; strStore[2] = "Three"; strStore[3] = "Four"; for (int i = 0; i < 10; i++) { Console.WriteLine(strStore[i]); } }
static void Main(string[] args) { StringDataStore strStore = new StringDataStore(); //creating an instance for class StringDataStore. strStore[0] = "One"; strStore[1] = "Two"; strStore[2] = "Three"; strStore[3] = "Four"; strStore[4] = "Five"; strStore[5] = "six" for (int i = 0; i < 10; i++) { Console.WriteLine(strStore[i]); } }