This Angular tutorial helps you get started with Angular quickly and effectively through many practical examples.

Default Access Modifiers in C#


In this article we are going to discuss Default Access Modifier in C#. There are many blogs, articles are available on the internet regarding Default Access Modifier but in this particular article I will try to explain to you with as much as simplest and realistic examples so you can get a clear idea of the Default Access Modifier use in C#.

Default Access Modifier

In C#, the default access modifier for members (fields, methods, properties, etc.) within a class or a struct is private. For top-level types (such as classes, interfaces, structs, and enums) that are declared directly within a namespace, the default access modifier is internal.

Here's a quick summary:

  1. Class members (methods, fields, properties, etc.) -  private by default.
  2. Top-level types (classes, interfaces, structs, enums) - internal by default.

Example


class MyClass
{
    int myField; // private by default
    void MyMethod() { } // private by default
}

class MyClass2 // internal by default
{
}


Next