I need a unique ID each time I create a new product.
My code creates same Guid (00000000-0000-0000-0000-000000000000) each item I add it to the list, and its not unique.
Can you tell me if I'm doing something wrong in this code please. Here is my code.
class Product
{
private Guid _ID ;
private String _Name = string.Empty;
private String _Price = string.Empty;
public Guid ID
{
get { return _ID; }
set { _ID = value; }
}
public string Name
{
get { return (_Name); }
set { _Name = value; }
}
public string Price
{
get { return (_Price); }
set { _Price = value; }
}
public Product(Guid ID, string Name, string Price)
{
_ID = ID;
_Name = Name;
_Price = Price;
}
public Product()
{
// TODO: Complete member initialization
}
public static void Main()
{
List<Product> productList = new List<Product>();
productList.Add(new Product() { Name = "shoe", Price = "80"});
productList.Add(new Product() { Name = "Hand Bag", Price = "180" });
productList.Add(new Product() { Name = "Pen", Price = "8" });
var cheapestItem = (from i in productList orderby i.Price descending select i.Name).Take(1);
Console.WriteLine(cheapestItem);
Console.ReadLine();
}