C# 编译错误:“X 由于其保护级别而无法访问" [英] C# compile error: “X is inaccessible due to its protection level”

查看:37
本文介绍了C# 编译错误:“X 由于其保护级别而无法访问"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#什么时候出现这个编译错误?

when c# gives this compile error?

'Favorite.Favorites.FavoriteCollection' 由于其保护级别而无法访问

'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);
    }
}

推荐答案

此编译时错误意味着您尝试访问的属性不是 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.

这篇关于C# 编译错误:“X 由于其保护级别而无法访问"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆