By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,724 Members | 863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,724 IT Pros & Developers. It's quick & easy.

Generics / Property Question

P: n/a
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; }
}
Dec 8 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Doug Handler" <dk*******@yahoo.com> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
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; }
}

Dec 8 '05 #2

P: n/a
Doug Handler <dk*******@yahoo.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 8 '05 #3

P: n/a
Nicholas,

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

dh
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Or****************@TK2MSFTNGP12.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Doug Handler" <dk*******@yahoo.com> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
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; }
}


Dec 9 '05 #4

P: n/a
Jon,

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

dh
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Doug Handler <dk*******@yahoo.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 9 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.