LINQ stands for Language-Integrated Query, which is made available to .NET programming languages from .NET 2.0. Coding using LINQ gives concise code and essentially it is a query where it does not get executed immediately until whenever needed.
The following code:
public class FileCollection : CollectionBase<string>
{
public override bool Contains(string item)
{
foreach (string str in this)
{
if (string.Compare(str, item, true) == 0)
return true;
}
return false;
}
}
can thus be converted nicely to LINQ:
public class FileCollection : CollectionBase<string>
{
public override bool Contains(string item)
{
return this.Any(str => string.Compare(str, item, true) == 0);
}
}
There is no performance difference so clearly the LINQ version is the winner!
–EOF (The Ultimate Computing & Technology Blog) —
162 wordsLast Post: Disallow Multiple Instance of Applications on The Same Machine (Windows Server) by Other User Sessions (Both C# and C++ solution)
Next Post: The Javascript Function to Compute the Stamp Duty Tax