hey I’m trying to upgrade my C# knowledge.
I’m learning to work with custom classes for inheritance and such…
i noticed two methods are most frequently used.
- setteres and getters like :
public class Item
{
public string _itemName;
public int _cost;
public string _description;
public Item()
{
_itemName = string.Empty;
_cost = 0;
_description = string.Empty;
}
public string ItemName
{
get { return _itemName; }
set { _itemName = value; }
}
public int Cost
{
get { return _cost; }
set { _cost = value; }
}
public string Description
{
get { return _description; }
set { _description = value; }
}
//some functions...
}
- constructors with overload like
public class Item
{
public string _itemName;
public int _cost;
public string _description;
//public bool _collectable;
public Item(string itemName, int cost, string description)
{
this._itemName = itemName;
this._cost = cost;
this._description = description;
}
// some functions...
}
assuming i didn’t get a total wrong idea about this… if so please do correct me.
thanks
J.