这篇是对象与集合操练,物件的创建,集合的一些基本功能,如添加,编辑,删除等功能。

 
对象,即是网店的商品物件,Insus.NET只为其添加2个属性,物件的ID的Key和名称ItemName以及2个构造函数,最后一个方法是重写ToString()方法。
C#集合Collections购物车Shopping Cart

 

 class Item
    {
        private int _key;
        public int Key
        {
            get
            {
                return _key;
            }
           set
            {
                _key = value;
            }
        }

        private string _ItemName;

        public string ItemName
        {
            get { return _ItemName; }
            set { _ItemName = value; }
        }

        public Item()
        {

        }

        public Item(int key, string itemName)
        {
            this._key = key;
            this._ItemName = itemName;
        }

        public override string ToString()
        {
            return string.Format("ID: {0}; Name: {1}。",_key,_ItemName);
        }
    }
Source Code

相关文章:

  • 2022-12-23
  • 2021-09-28
猜你喜欢
  • 2021-12-10
  • 2021-12-16
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
  • 2021-05-18
  • 2021-07-27
相关资源
相似解决方案