Generics / Property Question

  • Thread starter Thread starter Doug Handler
  • Start date Start date
D

Doug Handler

Hi (and thanks in advance)

I have a class called Person that i want to expose a public property called
Numbers. I have a class called PhoneNumbers that is a generic collection of
Phone. All i want to do is be able to access the Numbers property from
within Person. In other words, an individual (Person) can have multiple
PhoneNumbers. I'm getting the following error:
Error 1 Inconsistent accessibility: property type 'PhoneNumbers' is less
accessible than property 'Person.Numbers'

Here's the code:
in Person
.....
PhoneNumbers _phoneNumbers = new PhoneNumbers();

public PhoneNumbers Numbers
{
get {return this._phoneNumbers; }
set {this._phoneNumbers = value; }
}

in PhoneNumbers
....
List<Phone> _phoneList = new List<Phone>();

pubilc List<Phone> Phone
{
get { return this._phoneList; }
set { this._phoneList = value; }
}
 
Doug,

Do you have the PhoneNumbers class defined in the same class? If so,
then that type needs to be public, since you are going to expose a property
of that type. It is most likely defined as not public, hence the error.

Hope this helps.
 
Doug Handler said:
I have a class called Person that i want to expose a public property called
Numbers. I have a class called PhoneNumbers that is a generic collection of
Phone. All i want to do is be able to access the Numbers property from
within Person. In other words, an individual (Person) can have multiple
PhoneNumbers. I'm getting the following error:
Error 1 Inconsistent accessibility: property type 'PhoneNumbers' is less
accessible than property 'Person.Numbers'

Right. My guess is that your PhoneNumbers class is internal. Your
Numbers property is public, meaning that callers outside the assembly
can use it, even though they don't know anything about the PhoneNumbers
type.

Either make PhoneNumbers public, or make the Numbers property internal.
 
Nicholas,

I believe I discovered the problem - conflict of public access. Thanks for
getting back to me so quickly.

dh
Nicholas Paldino said:
Doug,

Do you have the PhoneNumbers class defined in the same class? If so,
then that type needs to be public, since you are going to expose a
property of that type. It is most likely defined as not public, hence the
error.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Doug Handler said:
Hi (and thanks in advance)

I have a class called Person that i want to expose a public property
called Numbers. I have a class called PhoneNumbers that is a generic
collection of Phone. All i want to do is be able to access the Numbers
property from within Person. In other words, an individual (Person) can
have multiple PhoneNumbers. I'm getting the following error:
Error 1 Inconsistent accessibility: property type 'PhoneNumbers' is less
accessible than property 'Person.Numbers'

Here's the code:
in Person
....
PhoneNumbers _phoneNumbers = new PhoneNumbers();

public PhoneNumbers Numbers
{
get {return this._phoneNumbers; }
set {this._phoneNumbers = value; }
}

in PhoneNumbers
...
List<Phone> _phoneList = new List<Phone>();

pubilc List<Phone> Phone
{
get { return this._phoneList; }
set { this._phoneList = value; }
}
 
Jon,

You were correct - thanks. I got all confused w/ the generic properties
within properties.

dh
 
Back
Top