C# Language Access Modifiers internal

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

The internal keyword makes a class (including nested classes), property, method or field available to every consumer in the same assembly:

internal class Foo
{
    internal string SomeProperty {get; set;}
}

internal class Bar
{
    var myInstance = new Foo();
    internal string SomeField = foo.SomeProperty;

    internal class Baz
    {
        private string blah;
        public int N { get; set; }
    }
}

This can be broken to allow a testing assembly to access the code via adding code to AssemblyInfo.cs file:

using System.Runtime.CompilerServices;

[assembly:InternalsVisibleTo("MyTests")]


Got any C# Language Question?