// Get count from the query.
int numb = (from g in currentVideoGames
where g.Length > 6
orderby g
select g).Count();
// numb is the value 5.
Console.WriteLine("{0} items honor the LINQ query.", numb);
}
Building a New Test Project
To begin digging into more intricate LINQ queries, create a new Console Application named
FunWithLinqExpressions. Next, define a trivial Car type, this time sporting a custom ToString()
implementation to quickly view the object’s state:
class Car
{
public string PetName = string.Empty;
public string Color = string.Empty;
public int Speed;
public string Make = string.Empty;
public override string ToString()
{
return string.Format("Make={0}, Color={1}, Speed={2}, PetName={3}",
Make, Color, Speed, PetName);
}
}
Now populate an array with the following Car objects within your Main() method:
static void Main(string[] args)
{
Console.WriteLine("***** Fun with Query Expressions *****\n");
Do'stlaringiz bilan baham: |