我正在使用接口引用变量来访问接口上的属性
但除此之外,实现接口的类还有自己的属性。
我无法通过此接口引用访问类属性。
以下是我的问题:
1)为什么会这样?
2)问题的解决方案是什么?有什么方法可以仅通过机器访问 AC 类的冷却剂功率变量吗?TYPE CAST 会起作用吗?
interface IMachines
{
#region properties
int machineID { get; set; }
static int totalID { get; set; }
string name { get; set; }
string make { get; set; }
int weight { get; set; }
int cost { get; set; }
int warranty { get; set; }
DateTime creationDate { get; set; }
#endregion
int generateWarrantyExpiry();
int searchMachine();
}
public class AC:IMachines
{
#region ACMembers
protected int _machineID;
protected string _name;
protected int _weight;
protected string _make;
protected DateTime _creationDate;
protected int _warranty;
protected int _cost;
public int _coolentPower;
public int CoolentPower
{
get { return _coolentPower; }
set { _coolentPower = value; }
}
#endregion
#region IMachines Members
public int machineID
{
get { return _machineID; }
set { _machineID = value; }
}
public string name
{
get { return _name; }
set { _name = value; }
}
public string make
{
get { return _make; }
set { _make = value; }
}
public int weight
{
get { return _weight; }
set { _weight = value; }
}
public int cost
{
get { return _cost; }
set { _cost = value; }
}
public int warranty
{
get { return _warranty; }
set { _warranty = value; }
}
public DateTime creationDate
{
get { return _creationDate; }
set { _creationDate = value; }
}
public int searchMachine()
{
//Search machine logic to be implemented
return 2
}
public void GenerateWarranty()
{
//generate warranty logic to be implemented
}
#endregion
}
}