自己学习的记录
通过set方法来设置属性,get方法来获取属性。
class Student
{
private string name;
private uint number;
public void SetName(string name)
{
this.name = name;
}
public void SetNumber(uint number) {
this.number = number;
}
public string GetName() {
return name;
}
public uint GetNumber() {
return number;
}
}
使用:
class C
{
public static void Main(string[] args)
{
Student s = new Student();
s.SetName("Mike");
s.SetNumber(23);
Console.WriteLine("student name:{0},number:{1}",s.GetName(),s.GetNumber());
}
}
class Student
{
private string name;
private uint number;
public string Name
{
set
{
name = value;
}
get
{
return name;
}
}
public uint Number
{
set
{
number = value;
}
get
{
return number;
}
}
}
使用:
class C
{
public static void Main(string[] args)
{
Student s = new Student();
s.Name = "Mike";
s.Number = 23;
Console.WriteLine("student name:{0},number:{1}",s.Name,s.Number);
}
}
今天新学的 还是不太理解 慢慢消化 ~~~~~