C # compilation error: "X is unavailable due to protection level"

when does C # give this compilation error?

'Favorite.Favorites.FavoriteCollection' is unavailable due to 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);
    }
}
+3
source share
2 answers

This compile-time error means that the property you are trying to access is not public, and the only way to access it is to either change its access modifier or use reflection .

+7
source

, : , , , interal (protected private), , :

public class FavoriteCollection
{
...
}
+3

Source: https://habr.com/ru/post/1762152/


All Articles