471,319 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Generics / Property Question

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
4 13950
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
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
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
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.

Similar topics

2 posts views Thread by Marc | last post: by
1 post views Thread by uttara | last post: by
5 posts views Thread by anders.forsgren | last post: by
1 post views Thread by Vladimir Shiryaev | last post: by
11 posts views Thread by hammad.awan_nospam | last post: by
4 posts views Thread by SHEBERT | last post: by
8 posts views Thread by mark.norgate | last post: by
7 posts views Thread by SpotNet | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.