Now that I am working with development in C# I have started looking into some .NET specific stuff. Right now I am deep diving into Language-Integrated Query, LINQ.
LINQ can often be used to replace loops where you iterate over a set of values and perform some kind of operation on the values that matches a certain criteria. For example, assume you have a large set of random integers and you want to extract those that are divisable by 7. The standard way to solve this is to use a for-loop and copy the numbers where n % 7 == 0.
With LINQ this becomes a one-liner:
var divisableBySeven = (from i in ints where (i % 7 == 0) select i).ToArray();
Pretty neet.
LINQ can often be used to replace loops where you iterate over a set of values and perform some kind of operation on the values that matches a certain criteria. For example, assume you have a large set of random integers and you want to extract those that are divisable by 7. The standard way to solve this is to use a for-loop and copy the numbers where n % 7 == 0.
With LINQ this becomes a one-liner:
var divisableBySeven = (from i in ints where (i % 7 == 0) select i).ToArray();
Pretty neet.
Kommentarer
Skicka en kommentar