using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Struct
{
class Program
{
struct Cat
{
private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
_Name = value;
}
}
public int Weight;
public string Colour;
}
static void Main(string[] args)
{
Cat ACat = new Cat( ); //新建Cat对象,并设置为ACat的值
ACat.Name = "Tom"; //通过属性Name设置ACat的名称
ACat.Weight = 5; //通过字段Weight设置ACat的体重
ACat.Colour = "Red"; //通过字段Colour设置ACat的颜色
//获取ACat的值,并打印到控制台
System.Console.WriteLine("This is CAT {0}, Weight is {1}, Colour is {2}",ACat.Name, ACat.Weight, ACat.Colour);
}
}
}
详情就不解释啦,一看代码就能懂,一步一步,加油!