Impact : Changing C# Methods from Private to Public

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.
Last updated:3/18/2015 8:28:41 AM

1 Answers

Samuel Fernandes
Samuel Fernandes

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() { }