主题:我这个索引为什么运行不了。
代码如下:
using System;
public class Test //声明一个数组
{
public string arr = new string[8];//声明一个8位数的字符串数组
public string this[int i] //声明一个索引器,索引器不支持static,索引器只支持实例
{
get
{
return arr[i]; //返回一个值
}
set
{
arr[i] = value; //value是属性值
}
}
}
public class MainExample
{
public static void Main()
{
Test strname = new Test();
strname[1] = "hello";
}
}
按照书上的敲出来的。
但是运行了 仔细看了下没发现什么错误。
谁帮我看看谢谢。
using System;
public class Test //声明一个数组
{
public string arr = new string[8];//声明一个8位数的字符串数组
public string this[int i] //声明一个索引器,索引器不支持static,索引器只支持实例
{
get
{
return arr[i]; //返回一个值
}
set
{
arr[i] = value; //value是属性值
}
}
}
public class MainExample
{
public static void Main()
{
Test strname = new Test();
strname[1] = "hello";
}
}
按照书上的敲出来的。
但是运行了 仔细看了下没发现什么错误。
谁帮我看看谢谢。