C# 编译错误:“X 由于其保护级别而无法访问”
当c#给出这个编译错误时?
“Favorite.Favorites.FavoriteCollection”由于其保护级别而无法访问
private void Form1_Load(object sender, EventArgs e)
{
Favorites objFavorites = new Favorites();
objFavorites.ScanFavorites();
foreach (WebFavorite objWebFavorite in objFavorites.FavoriteCollection)
{
ListViewItem objListViewItem = new ListViewItem();
objListViewItem.Text = objWebFavorite.Name;
objListViewItem.SubItems.Add(objWebFavorite.Url);
lstFavorites.Items.Add(objListViewItem);
}
}
when c# gives this compile error?
'Favorite.Favorites.FavoriteCollection' is inaccessible due to its protection level
private void Form1_Load(object sender, EventArgs e)
{
Favorites objFavorites = new Favorites();
objFavorites.ScanFavorites();
foreach (WebFavorite objWebFavorite in objFavorites.FavoriteCollection)
{
ListViewItem objListViewItem = new ListViewItem();
objListViewItem.Text = objWebFavorite.Name;
objListViewItem.SubItems.Add(objWebFavorite.Url);
lstFavorites.Items.Add(objListViewItem);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此编译时错误意味着您尝试访问的属性不是
public
,访问它的唯一方法是修改其 访问修饰符 或使用 反射。This compile-time error means that the property you are trying to access is not
public
and the only way to access it is by either modifying its access modifier or using reflection.当它的可见性不足以到达时:例如,如果该类位于另一个项目中,并且可见性为
interal
或更低(protected
或private
),您将无法使用它。在这种情况下,您必须将其更改为公开:When it's not visible enough to reach: If, for example, the class is in another project and the visibility is
interal
or lower (protected
orprivate
), you won't be able to use it. You'll have to change it to public in such a case: