Saturday, March 3, 2018

Linq is fun

Recently I used some LINQ in Visual Basic .NET to search through data structures such as Array and Lists.

//check if list contains a particular object with two property values equal to x and y respectively.
objectArray.ToList.Find(Function(objectItem) objectItem.PropertyOne = x AndAlso objectItem.PropertyTwo = y)
//remove specific notification objects from list of notification objects list
objectArray.RemoveAll(Function(objectItem) objectItem.PropertyOne = x)
//creates a new array without a particular item in the original array
objectArray = objectArray.Where(Function(objectItem) objectItem.PropertyOne <> x).ToArray()


Definitely helps with brevity of the code and has a cool syntax. But I am not so sure about performance. I think it still uses loops internally. I will keep updating this as I use more and more LINQ. More to follow...

No comments:

Post a Comment