私は3つのプロパティを持つクラス「製品」を持っています。ユーザーが 3 つのレコードを指定すると、それがリストに表示される単純なコンソール アプリケーションです。クラスの商品からリストを作成したのですが、なぜか無限エントリーになってしまいました!何が間違っているのかわからない
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Product obj1 = new Product();
}
}
class Product
{
public int ID { get; set; }
public string Name { get; set; }
public string Price { get; set; }
public Product()
{
Console.WriteLine("Enter Product Name: ");
string name = Console.ReadLine();
Console.WriteLine("Enter Product Price: ");
string price = Console.ReadLine();
List<Product> MyList = new List<Product>();
MyList.Add(new Product() { ID = 1, Name = name, Price = price });
foreach(var item in MyList)
{
Console.WriteLine("ID "+item.ID + " Name "+item.Name);
}
} //end product class
}