Home > DeveloperSection > Forums > Impact : Changing C# Methods from Private to Public
Mahesh KK
Mahesh KK

Total Post:4

Posted on    March-18-2015 6:32 AM

 C# C#  Windows Controls  Windows 7  .Net Assembly  Class 

 1 Reply(s)
 918  View(s)
Rate this:
Hello All,

i have a Windows form application based on C#, i would like to change few of its methods from Private to Public in order to use them in Matlab, I am quite new to handle this, please let me know how it will impact my application?
Is there any consequences? is it safe to do that?

Thanks in advance.

Samuel Fernandes
Samuel Fernandes

Total Post:159

Posted on    March-18-2015 8:28 AM

No, you can hide a public member with a private method in a subclass, but you cannot override a public member with a private one in a subclass. And, in actually, it's not just a public/private thing, this applies to narrowing the access in general.


Revised: By hiding with a more restrictive access - in this case private access - you will still see the base class member from a base-class or sub-class reference, but it would defer to the new method when available from the new access level.


So in general, when you hide, the hide takes precedence when visible at its access level. Otherwise the original method is the one used.


public class BaseClass


    public virtual void A() { }


    public virtual void B() { }



public class SubClass


    // COMPILER ERROR, can't override to be more restrictive access

    private override void A() { }


    // LEGAL, you can HIDE the base class method, but which is chosen

    // depends on level accessed from

    private new void B() { }


Don't want to miss updates? Please click the below button!

Follow MindStick