C#编译错误:“X是人迹罕至,由于其保护级别” [英] C# compile error: “X is inaccessible due to its protection level”

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

问题描述

在C#中给出了这样的编译错误?




Favorite.Favorites.FavoriteCollection'不可访问由于其保护级别




 私人无效Form1_Load的(对象发件人,EventArgs五)
{
收藏objFavorites =新贵();

objFavorites.ScanFavorites();
的foreach(WebFavorite objWebFavorite在objFavorites.FavoriteCollection)
{
ListViewItem的objListViewItem =新的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);
    }
}

解决方案

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天全站免登陆