Languages
[Edit]
EN

C# / .NET - uppercase all List elements

0 points
Created by:
Nabila-Burnett
385

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

References

  1. Enumerable.Select Method (System.Linq) | Microsoft Docs
  2. String.ToUpper Method (System) | Microsoft Docs
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join