views:

155

answers:

2

hi, 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);
    }
}
+7  A: 

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.

Darin Dimitrov
this problem is just in form1.cs
arash
@arash, and what you expect us to do?
Darin Dimitrov
@arash: The problem is in form1.cs because that's where you access the `FavoriteCollection` property of `objFavorites`. You need to modify the definition of that property if you want other classes (like `Form1`) to be able to access it.
grossvogel
thanks it worked.i added a public to array list
arash
+3  A: 

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
{
...
}
Excel20
ita an arraylist.i used it in another project,so i renamed in to another name but it also has the same error
arash