Reputation: 116
I have the following error
CS0053 Inconsistent accessibility: property type '
List<Koers>
' is less accessible than property 'DataStorage.deKoers
'
This issue is similar to other posts; yet i cannot find the proper solution:
I suspect the List to play an unexpected role; as it works with the "MyText" property.
DataStorage instStorage = new DataStorage();
private void LadenInventarisVanDisk()
{
var x = instStorage.MyText;
Console.WriteLine(x.ToString() );
}
namespace Storage
{
public class DataStorage
{
/* this works fine*/
private string _myText = "text to save" ;
public string MyText
{
get { return _myText; }
set { _myText = value; }
}
private List<Inventaris> _deLijst;
/* adding public generate the accessible error*/
public List<Inventaris> DeLijst
{
get { return _deLijst; }
set { _deLijst = value; }
}
private List<Koers> _deKoers;
/* excluding the public means i cannot call this property from another location */
List<Koers> deKoers
{
get { return _deKoers; }
set { _deKoers = value; }
}
}
}
Upvotes: 2
Views: 660
Reputation: 512
The accessibility of a List<T>
is determined by the accessibility of a given T
, therefore your classes Koers
and Inventaris
have to be publicly accessible for a List<Koers
/ List<Inventaris>
to be returned by your properties, as a property cannot be more visible than the object that it is returning.
See this for another examle.
So your classes have to be declared like this:
public class Koers
{
//Class code here
}
public class Inventaris
{
//Class code here
}
EDIT: As suggested by Chris, I clarified my answer a bit.
Upvotes: 5
Reputation: 638
The answer is likely that the classes Inventaris
and / or Koers
are less accessible than public (default accessibility for classes is internal
if in not nested and private
if nested.) Both are more restrictive than public and will raise the error). A good way to fix this is always explicitly writing the access level for everything - it makes these kind of bugs easier to see
Upvotes: 1