开发者

C# compile error: “X is inaccessible due to its protection level”

开发者 https://www.devze.com 2023-01-13 19:59 出处:网络
when c# gives this compile error? \'Favorite.Favorites.FavoriteCollection\' is inaccessible due to its protection level

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(objWebFav开发者_开发技巧orite.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.


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 or private), you won't be able to use it. You'll have to change it to public in such a case:

public class FavoriteCollection
{
...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消