In this post, we will do a quick review of LINQ operators Any() and All().
Question 1: Using LINQ, determine if any word in a list contains the substring “ei”.
string[] words = { "believe", "relief", "receipt", "field" };
bool iAfterE = words.Any(w => w.Contains("ei"));
Console.WriteLine("list has words that contains 'ei': {0}", iAfterE);
Question 2: Using LINQ, return a grouped list of products only for categories that have at least one product that is out of stock.
In this case, we run any over a grouping as shown below:
List<Product> products = GetProductList();
var productGroups =
from p in products
group p by p.Category into g
where g.Any(p => p.UnitsInStock == 0)
select new { Category = g.Key, Products = g };
Question 3: Determine if an array of numbers contains all odds.
int[] numbers = { 1, 11, 3, 19, 41, 65, 19 };
bool onlyOdd = numbers.All(n => n % 2 == 1);
Console.WriteLine("The list contains only odd numbers: {0}", onlyOdd);
Question 4: Using LINQ, return a grouped list of products only for categories that have all of their products in stock.
List<Product> products = GetProductList();
var productGroups =
from p in products
group p by p.Category into g
where g.All(p => p.UnitsInStock > 0)
select new { Category = g.Key, Products = g };
good article
ReplyDeletesanjay gupta
I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai
Deleteexcellent
ReplyDeleteVery good... thanks.
ReplyDeleteMore please!
ReplyDeleteThe blog or and best that is extremely useful to keep I can share the ideas
of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
tanki online | 2048 game|
Extremely hard to reveal these helpful page or site. I have numerous gadgets and accomplishing legitimate article of these worked admirably and vitality keeps on being seeing about this web blog. You can use this assignment writing service for any kind of essay writing work.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThanks for the great post! Your QAs have been added to the www.fullstack.cafe portal and back-linked!
ReplyDeleteThanks for such a good article on LinQ Interview Questions
ReplyDeleteAivivu - đại lý chuyên vé máy bay trong nước và quốc tế
ReplyDeleteve may bay di my gia re
vé máy bay từ los angeles về việt nam
ve may bay tư duc ve viet nam
ve may bay tu nga ve viet nam
vé máy bay từ anh về việt nam
chuyến bay từ paris về hà nội
khách sạn cách ly ở nha trang