471,075 Members | 716 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

problem with accessrights when having a class in another class

Hello!

I access the class MyComparer in this way.
steel_post.Sort(new MeltPracDataComposition.Composition.MyComparer());

You can see the class definition for MyComparer below.
As you can see this class MyComparer in located withing class Composition
and this
class Composition is located within class MeltPracDataComposition.

Now to my problem if I use the default which I thing is internal on the
class definition for class MyComparer I get this compile error.
C:\PK\Development\Products\UTCAS\4.0\SRC\MeltPracA pplication\Dialog\Composit
ionForm.cs(456):
'MeltPracData.MeltPracDataComposition.Composition. MyComparer' is
inaccessible due to its protection level

But if I prefix the class MyComparer with the keword internal I don't get
any compile error.
As I have understood is the default on class definition always internal so
if that is the case
I wouldn't have got these compile errors when using the default.

Can somebody explain why I got compile error when using the default
especially when
the default is internal and when using the internal I don't get any compile
errors.

public class MeltPracDataComposition : MeltPracData
{
public class Composition : IComparable
{
...

class MyComparer : IComparer
{
region IComparer Members
public int Compare(object x, object y)
{
return
((Composition)x).Order.CompareTo(((Composition)y). Order );
}
#endregion
}// end class MyComparer
}// end class Composition
}//end class MeltPracDataComposition

//Tony
Aug 31 '06 #1
1 1225
Hi tony,

the default accessabilty of any class or struct member (including nestet
types) is allways private.
Only for Toplevel types (= not nested) the default is internal.

The intuitive rule is: default accessability is allways "as private as
possible".

hth

"tony" <jo*****************@telia.comschrieb im Newsbeitrag
news:O7**************@TK2MSFTNGP03.phx.gbl...
Hello!

I access the class MyComparer in this way.
steel_post.Sort(new MeltPracDataComposition.Composition.MyComparer());

You can see the class definition for MyComparer below.
As you can see this class MyComparer in located withing class Composition
and this
class Composition is located within class MeltPracDataComposition.

Now to my problem if I use the default which I thing is internal on the
class definition for class MyComparer I get this compile error.
C:\PK\Development\Products\UTCAS\4.0\SRC\MeltPracA pplication\Dialog\Composit
ionForm.cs(456):
'MeltPracData.MeltPracDataComposition.Composition. MyComparer' is
inaccessible due to its protection level

But if I prefix the class MyComparer with the keword internal I don't get
any compile error.
As I have understood is the default on class definition always internal so
if that is the case
I wouldn't have got these compile errors when using the default.

Can somebody explain why I got compile error when using the default
especially when
the default is internal and when using the internal I don't get any
compile
errors.

public class MeltPracDataComposition : MeltPracData
{
public class Composition : IComparable
{
...

class MyComparer : IComparer
{
region IComparer Members
public int Compare(object x, object y)
{
return
((Composition)x).Order.CompareTo(((Composition)y). Order );
}
#endregion
}// end class MyComparer
}// end class Composition
}//end class MeltPracDataComposition

//Tony


Aug 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by endus | last post: by
4 posts views Thread by Leslaw Bieniasz | last post: by
reply views Thread by Lucas, Todd | last post: by
5 posts views Thread by Keith Jakobs, MCP | last post: by
9 posts views Thread by norvinl | last post: by
13 posts views Thread by Rainer Queck | last post: by
2 posts views Thread by Jeff | last post: by
12 posts views Thread by sheldonlg | 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.