Convert elements in List in CSharp

Description

The following code shows how to convert elements in List.

Example


using System;//from   w  w  w .j av a 2  s  . c  o m
using System.Collections;
using System.Collections.Generic;

class Sample
{
    public static void Main()
    {
        //Create a List of Strings
        //String-typed list
        List<string> words = new List<string>();  

        words.Add("A");
        words.Add("B");
        words.Add("C");
        words.Add("D");
        words.Add("E");
        words.Add("F");

        List<string> upperCastWords = words.ConvertAll(s => s.ToUpper()); 
        List<int> lengths = words.ConvertAll(s => s.Length);
   }
}




















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary