You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
847 B

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace State_VendingMachineExample
{
internal class Product
{
private List<Item> items;
public Product()
{
items = new List<Item>()
{
new Item() { Id = 101, Price = 3.50M },
new Item() { Id = 201, Price = 4.50M },
new Item() { Id = 301, Price = 4.50M }
};
}
public decimal? GetPrice(int itemId)
{
Item item = items.SingleOrDefault(x => x.Id == itemId);
return item == null ? null : (decimal?)item.Price;
}
private class Item
{
public int Id { get; set; }
public decimal Price { get; set; }
}
}
}