为啥出错,,

xiaotuzi xiaotuzi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
xiaotuzi
C# 111,129 成员 642,539 内容