我有 3 个课程,Insurance、Employee 和 InsuranceTest。
Insurance 调用 Employee 类,InsuranceTest 必须通过提示用户提供信息来使用给定的构造函数创建 2 个对象来测试代码。
保险代码类别:
namespace IT
{
class Insurance
{
private int cust;
private string agent;
string state;
public Insurance (int cust, string agent, string state )
{
this.cust = cust;
this.agent = agent;
this.state = state;
}
public Insurance ( int cust, string agent)
: this( cust, agent, "")
{
}
public int Cust
{
get { return cust; }
set { cust = value; }
}
public string Agent
{
get { return agent; }
set { agent = value; }
}
public string State
{
get { return state; }
set { state = value; }
}
Employee e1 = new Employee("Susi", "Insurance Agent Ave SW", 77582);
}
}
雇员类【保险类用信息调用这个类):
namespace IT
{
class Employee
{
string name;
string address;
private int id;
public Employee(string name, string address, int id)
{
this.name = name;
this.address = address;
this.id = id;
}
public Employee(string name, string address)
: this( name, address, 0)
{
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Address
{
get { return address; }
set { address = value; }
}
public int Id
{
get { return id; }
set { id = value; }
}
}
}
InsuranceTest 类(我正在努力使用的代码,它必须提示用户提供信息以使用在显示代理信息、客户数量、本地状态时给出的构造函数[假设员工和保险类]创建 2 个对象
namespace IT
{
class InsuranceTest
{
static void Main(string[] args)
{
Insurance i1 = new Insurance(5, "Random Insurance", "PA");
}
}
}
查看评论,您的 SetCustomers 方法不存在。你可以简单地这样做:
i1.Cust = 10; // you can use non zero value instead of 0 to see if Cust is set
要打印 cust,您可以简单地执行以下操作:
Console.WriteLine(i1.Cust);
C# getter 和 setter 以及属性的 MSDN 在这里:https : //docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句