EN
C# / .NET - uppercase all List elements
0
points
In this article, we would like to show you how to uppercase all List elements in C#.
Quick solution:
List<string> myList = new List<string> { "a", "b", "c" };
myList = myList.Select(x => x.ToUpper()).ToList();
Practical example
In this example, we select all items from myList and uppercase them using ToUpper() method.
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
List<string> myList = new List<string> { "a", "b", "c" };
// uppercase all elements
myList = myList.Select(x => x.ToUpper()).ToList();
// display result
myList.ForEach(x => Console.WriteLine(x));
}
}
Output:
A
B
C