Follow by Email

Wednesday, 23 October 2013

how to remove item from string array

In this way using Linq we can do this:

In VB.Net :

Dim myArray As String() = New String(2) {}
myArray(0) = "Hello World"
myArray(1) = "This is a sample code"
myArray(2) = "Delete me"

myArray = myArray.Where(Function(w) w <> myArray(2)).ToArray()



In C# :

string[] myArray = new string[3];
            myArray[0] = "Hello World";
            myArray[1] = "This is a sample code";
            myArray[2] = "Delete me";

            myArray = myArray.Where(w => w != myArray[2]).ToArray(); 


0 comments:

Post a Comment


                                                            

 
Design by Abhinav Ranjan Sinha