Does C# have the equivalent of Delphi's private modifier -


in delphi, private modifier unique:

contoso = class private    procedure dostuff(); end; 

you think has c# equivalent of:

class contoso {    private void dostuff()    {    } } 

but in delphi, private keyword more unit friend. in other words, other classes in same code file can access private members. transcoding delphi c#, equivalent of following code working:

public class contoso {    private void dostuff()    {    } }  internal class fabrikam {    contoso _contoso;     //constructor    fabrikam()    {       _contoso = new contoso();       _contoso.dostuff(); //i can call private method of class    } } 

even though method dostuff private contoso, other classes in same file can call method.

what don't want make method internal:

class contoso {    internal void dostuff(); } 

because other code in assembly can see or call dostuff method; don't want.


does c# support sort of unit friend or unit internal access modifier?

not exactly.

in c# can declare member internal , gives classes (code) in same assembly access member. has more or less same usage delphi's unit access rule.

the scope wider have more control.

you state don't want this, think use cases. in delphi unwillingly giving access all private members. , prevented putting each class in own unit.

in .net, assembly 1 project , managing unwanted acces inside 1 assembly easy. putting fence rest of world more important.

you cannot limit on file boundary because file has no significance in c#. file boundary not present in il, , rule conflict partial classes 1 thing.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -