Q:

sum of an element of items using one linq command

I have a List ListOfGames where VideoGame is:
public class VideoGame{
   public string Title;
   public string Platform;
   public string PublishingCompany;
   public int InStock; //this is how many that we have in stock
   public decimal Price;
   public int GameID; //this is the ID of a specific title. For example: all DOOM games have   id of say 234 regardless of platform.
   //etc.
}

I want to get the total amount of VideoGames we have in stock for a certain game using a simple Sum Query with LINQ.
I tried:
int stock = ListOfGames.Sum(e=>e.InStock == GameID); 
//GameID is a param that refers to the id of the game.

but that does not return the correct value.
I looked at this question: Sum properties using LINQ, but it does not help. Any ideas on how to get the sum of the quantity of all the games in stock for a certain GameID?

A:

int stock = ListOfGames.Where(x=>x.Id == GameID).Sum(x=>x.Instock);

A:

Here is my suggestion:
int stock = ListOfGames.Where(e => e.GameID == GameID).Sum(e => e.InStock);

