problem with accessrights when having a class in another class

  • Thread starter Thread starter tony
  • Start date Start date
T

tony

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\MeltPracApplication\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
 
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
 
Back
Top