There are many situations where you want to convert List<int> to List<string>.
Using Linq Method "ConvertAll" we can achieve in one sentence.
LINQ Namespace is System.Linq .
Here are sample Example For this:
C# Example :
Here ConvertAll methods accepts a deligate and return converted list.
VB.net Example :
Using Linq Method "ConvertAll" we can achieve in one sentence.
LINQ Namespace is System.Linq .
Here are sample Example For this:
C# Example :
List<int> l1 = new List<int>(new int[] { 1, 2, 3 });
List<string> l2 = l1.ConvertAll<string>(delegate(int i) { return i.ToString(); });
List<string> l2 = l1.ConvertAll<string>(delegate(int i) { return i.ToString(); });
Here ConvertAll methods accepts a deligate and return converted list.
VB.net Example :
Dim l1 As New List(Of Integer)(New Integer() {1, 2, 3})
Dim l2 As List(Of String) = l1.ConvertAll(Of String)(Function(i As Integer) i.ToString())
Dim l2 As List(Of String) = l1.ConvertAll(Of String)(Function(i As Integer) i.ToString())
No comments:
Post a Comment