Languages
[Edit]
EN

C# / .NET - lowercase all List elements

0 points
Created by:
Mohammad-Oneal
327

In this article, we would like to show you how to lowercase all List elements in C#.

Quick solution:

List<string> myList = new List<string> { "A", "B", "C" };

myList = myList.Select(x => x.ToLower()).ToList();

 

Practical example

In this example, we select all items from myList and lowercase them using ToLower() 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" };

        // lowercase all elements
        myList = myList.Select(x => x.ToLower()).ToList();

        // display result
        myList.ForEach(x => Console.WriteLine(x));
    }
}

Output:

a
b
c

References

  1. Enumerable.Select Method (System.Linq) | Microsoft Docs
  2. String.ToLower 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