Given the output of query:
var queryResult = from o in objects
where ...
select new
{
FileName = o.File,
Size = o.Size
}
What would you consider the neatest way to detect if a file is in the queryResult? Here is my lame try with LINQ:
string searchedFileName = "hello.txt";
var hitlist = from file in queryResult
where file.FileName == searchedFileName
select file;
var contains = hitlist.Count() > 0;
There must be an more elegant way to figure out the result.
To check for an element in a string, use the Contains() method. The following is our string array. string[] arr = { "Java", "C++", "Python"}; Now, use Contains() method to find a specific string in the string array.
There are the following two ways to write LINQ queries using the Standard Query operators, in other words Select, From, Where, Orderby, Join, Groupby and many more. Using lambda expressions. Using SQL like query expressions.
string searchedFileName = "hello.txt";
var contains = queryResult.Any(file => file.FileName == searchedFileName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With