In the example below, why is product null?
using System.Collections.Generic;
using System.Linq;
namespace TestEventsds343
{
public class Program
{
static void Main(string[] args)
{
Product product = Product.LoadProduct(222);
}
}
public class Product
{
public int ProductNumber { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public static Product LoadProduct(int productNumber)
{
List<Product> products = new List<Product>();
products.Add(new Product { ProductNumber = 111, Name = "Intel CPU", Description = "Newest model, very fast." });
products.Add(new Product { ProductNumber = 222, Name = "Philips Monitor", Description = "22-inch, very nice." });
products.Add(new Product { ProductNumber = 333, Name = "Sony Camera", Description = "10 Megapixels, sharp pictures." });
return products.Where(p => p.ProductNumber == productNumber) as Product;
}
}
}