Here is an example code in C# that sorts a list of strings in alphabetical order:
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
List<string> names = new List<string>() {"John", "Alice", "Bob", "Mary"};
names.Sort();
foreach (string name in names)
{
Console.WriteLine(name);
}
}
}
The List<T>.Sort
method is used to sort the list of strings in-place. The foreach
loop is used to print the sorted list.
Asked: 2021-05-30 11:00:00 +0000
Seen: 1 times
Last updated: Jan 07 '23