List GetExclusiveProducts(List source)
=> source
.Where(p => p.ProductTitle == "iPhone")
.OrderBy(p => p.TypeOfPhone)
.ToList();
(You could join the first two lines, but I think that’s ugly for multi-line expressions.)Also, less lines is not a good argument for SQL-style syntax vs method-call syntax. The good argument is that the SQL-style syntax is limited to only a few basic operations, when there are many more useful methods available.
Another reason is that this does not compile:
List GetExclusiveProducts(List source)
{
return from p in source
where p.ProductTitle == "iPhone"
orderby p.TypeOfPhone
select p;
}
This method returns IOrderedEnumerable, not a list. To fix it, you would need to either change the return type, or go outside of the SQL-style syntax and call the ToList method: return (from ... select p).ToList();