kodingwindow@kw:~/csharp$ dotnet run
Pineapple Apple Orange Mango Grapes Cherry Apple
Size: 7
Capacity: 8
kodingwindow@kw:~/csharp$
Implementation of C# List class: Sort() and Reverse() methods
Program.cs
usingSystem.Collections.Generic;List<string>li=newList<string>();li.Add("Apple");li.Add("Orange");li.Add("Mango");li.Add("Grapes");li.Add("Cherry");li.Add("Apple");li.Sort();for(inti=0;i<li.Count;i++){Console.Write(li[i]+" ");}Console.WriteLine();li.Reverse();for(inti=0;i<li.Count;i++){Console.Write(li[i]+" ");}Console.WriteLine();li.Reverse(2,4);//li.Reverse(int index, int count)for(inti=0;i<li.Count;i++){Console.Write(li[i]+" ");}Console.WriteLine();
Output
kodingwindow@kw:~/csharp$ dotnet run
Apple Apple Cherry Grapes Mango Orange
Orange Mango Grapes Cherry Apple Apple
Orange Mango Apple Apple Cherry Grapes
kodingwindow@kw:~/csharp$
Implementation of C# List class: Remove(), RemoveAt(), and Clear() methods
Program.cs
usingSystem.Collections.Generic;List<string>li=newList<string>();li.Add("Apple");li.Add("Orange");li.Add("Mango");li.Add("Grapes");li.Add("Cherry");li.Add("Apple");li.Remove("Apple");li.RemoveAt(0);for(inti=0;i<li.Count;i++){Console.Write(li[i]+" ");}li.Clear();if(li.Count==0){Console.WriteLine("\nList is empty now");}
Output
kodingwindow@kw:~/csharp$ dotnet run
Mango Grapes Cherry Apple
List is empty now
kodingwindow@kw:~/csharp$
Implementation of C# List class: IndexOf() and LastIndexOf() methods
Program.cs
usingSystem.Collections.Generic;List<string>li=newList<string>();li.Add("Apple");li.Add("Orange");li.Add("Mango");li.Add("Grapes");li.Add("Cherry");li.Add("Apple");li.Add("Apple");Console.WriteLine("First match at: "+li.IndexOf("Apple"));Console.WriteLine("Last match at: "+li.LastIndexOf("Apple"));
Output
kodingwindow@kw:~/csharp$ dotnet run
First match at: 0
Last match at: 6
kodingwindow@kw:~/csharp$
Implementation of C# List class: IndexOf() and LastIndexOf() methods
Dear User, Thank you for visitng Kodingwindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.
Dear User, We are grateful for your interest in the Kodingwindow Android app. We intend to soon make it available on the Google Play Store. Currently, Android versions 10 and up require manual apk installations. Would you like to get the app?