473,473 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 14004
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marc | last post by:
Given a class 'Invoice' with a property 'public IMyColl<IInvoiceLine> InvoiceLines' where 'IMyColl<T> : IList<T>' i would like to detect by reflection that 'InvoiceLines' is a...
12
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as...
1
by: uttara | last post by:
I have a generic collection which I am using in classes to store a collection of embedded objects. Class Employee: IEntity { Private string mName; Private int mEmployeeID; …. Private...
5
by: anders.forsgren | last post by:
This is a common problem with generics, but I hope someone has found the best way of solving it. I have these classes: "Fruit" which is a baseclass, and "Apple" which is derived. Further I have...
1
by: Vladimir Shiryaev | last post by:
Hello! Exception handling in generics seems to be a bit inconsistent to me. Imagine, I have "MyOwnException" class derived from "ApplicationException". I also have two classes...
11
by: hammad.awan_nospam | last post by:
Hello, I'm wondering if it's possible to do the following with Generics: Let's say I have a generic member variable as part of a generic class like this: List<DLinqQuery<TDataContext>>...
4
by: SHEBERT | last post by:
Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox. Why? If I use List and generic List<>,...
8
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem...
7
by: SpotNet | last post by:
Hello NewsGroup, Reading up on Generics in the .NET Framework 2.0 using C# 2005 (SP1), I have a question on the application of Generics. Knowingly, Generic classes are contained in the...
3
by: Dmitry Nogin | last post by:
Hi, I would like to use dictionaries to implement my property value storing mechanics. (I have a lot but many of them are just about to keep <nullmost of the time, so it might save a lot of...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.