| 看着杨老师视频关于索引器 不理解 请求大家帮助啊  把这个程序解释一下吧,有点理解不了 namespace 索引
 {
 class program
 {
 static void main(string[] args)
 int[] values={1,2,4,6};//这里声明数组是干什么的啊?
 int i=values[1];
 Person p1= new Person();
 p1[1]="小明"//这个语法是怎么回事啊?
 Console.WriteLine(p1[1]+p1[2]);
 console.ReadKey();
 }
 class Person
 {
 private string FirstName="大猫"
 private  string SecondName="二毛"
 public string this[int index]
 {set
 {
 if(index==1)
 {FirstName=value;}
 else if(index==2)
 {SecondName=value;}
 else
 {
 throw new Exception("错误的序列号");
 }
 }
 get
 {
 if(index==1){return FristName;}
 else if (index==2){return SecondName;}
 else
 {
 throw new Exception("错误的序号");
 }
 }}
 
 
 |