类问题
using System;
public class Customer
{
public enum sex
{
man,
woman,
};
private string s_name;
public string Name{
get{
return s_name;
}
}
private sex m_sex;
public sex Sex{
get{
return m_sex;
}
}
private string s_no;
public string No{
get{
return s_no;
}
set{
if(s_no!=value){
s_no=value;
}
}
}
private int i_day;
public int Day{
get{
return i_day;
}
set{
if(i_day!=value){
i_day=value;
}
}
}
public void Customer(string name,sex sex,string no,int day)
{
s_name=name;
m_sex=sex;
s_no=no;
i_day=day;
}
public static void Main()
{
Customer c1=new Customer( "Jake Son ", "man ", "201 ", "21 ");
Console.WriteLine( "Name:{0} Sex:{1} ",c1.s_name,c1.sex);
Console.WriteLine( "RoomNO:{0} Day:{1} ",c1.s_no,c1.i_day);
}
}
问?为什么编译不通过呢?
怎么改,谢谢!
------解决方案--------------------using System;
public class Customer
{
public enum sex
{
man,
woman,
};
private string s_name;
public string Name
{
get
{
return s_name;
}
}
private sex m_sex;
public sex Sex
{
get
{
return m_sex;
}
}
private string s_no;
public string No
{
get
{
return s_no;
}
set
{
if(s_no!=value)
{
s_no=value;
}
}
}
private int i_day;
public int Day
{
get
{
return i_day;
}
set
{
if(i_day!=value)
{
i_day=value;
}
}
}
//构造函数没有返回值 去了void
public Customer(string name,sex sex,string no,int day)
{
s_name=name;
m_sex=sex;
s_no=no;
i_day=day;
}
public static void Main()
{
//注意枚举类型和整数类型
Customer c1 = new Customer( "Jake Son ",sex.man, "201 ",21);
//c1.Sex是成员 不应该是c1.sex 你这里小写的sex是类型
Console.WriteLine( "Name:{0} Sex:{1} ",c1.s_name,c1.Sex);
Console.WriteLine( "RoomNO:{0} Day:{1} ",c1.s_no,c1.i_day);
}
}
------解决方案--------------------public void Customer(string name,sex sex,string no,int day)
晕,构造函数怎么有void?构造函数没有返回值的
改为
public Customer(string name,sex sex,string no,int day)