method without access modifier

前端 未结 8 840
走了就别回头了
走了就别回头了 2020-12-05 22:21

Ok this is bugging me.. I know I\'ve read it somewhere and google isn\'t helping.

What is the accessibility level of a method that does not specify an access modifie

相关标签:
8条回答
  • 2020-12-05 22:59

    Oh wait, there's one more thing ....

    interface method declarations are of course public by definition. So the following implementation is public, without an explicit access modifier.

    public class MyClass : IEqualityComparer<MyClass>
        bool IEqualityComparer<MyClass>.Equals(MyClass x , MyClass y) {}
    }
    
    0 讨论(0)
  • 2020-12-05 23:05

    Yes, internal is the default for classes, but private is the default for members.

    0 讨论(0)
  • 2020-12-05 23:06

    Class methods are private and sealed by default in .NET. This means the method is only visible within the class and cannot be overridden by the inherited class.

    0 讨论(0)
  • 2020-12-05 23:06

    hope this clarifies all as per screenshot directly from MSDN

    0 讨论(0)
  • 2020-12-05 23:07

    For a class: Internal is the default if no access modifier is specified.

    For a method: Private is the default if no access modifier is specified.

    0 讨论(0)
  • 2020-12-05 23:14

    Assuming this is a C# method, since you have the ".net" tag.

    People need to differentiate between "member" accessibility and "class" accessibility.

    • The default accessibility of class members (including methods) in C# is private. See https://msdn.microsoft.com/en-us/library/ba0a1yw2(v=vs.140).aspx
    • The default accessibility of a class itself is internal.
    0 讨论(0)
提交回复
热议问题