为啥出错,,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Chapter9
{
class Class1
{
private string[] students = { "Tom", "Alice", "Jack" };
static void Main()
{
var obj = new ClassExample16();
for (int i = 0; i < obj.students.Length; i++)
{
Console.WriteLine(obj[i]);
Console.ReadKey();
}
}
}
class classexample16
{
public string[] students = { "Tom", "Alice", "Jack" };
public string this[int studentNo]
{
get
{
return students[studentNo];
}
set
{
students[studentNo] = value;
}
}
}
}
编译后,错误 1 “Chapter9.ClassExample16.students”不可访问,因为它受保护级别限制 E:\CSharp4_DefinitiveGuide_Source4\Chapter9\Class1.cs 14 37 Chapter9
------解决方案--------------------