using System;
namespace ClassLibrary1{public class SameAssemblyBaseClass{public string publicVariable = "public";protected string protectedVariable = "protected";protected internal string protected_InternalVariable = "protected internal";internal string internalVariable = "internal";private string privateVariable = "private";public void test(){// OKConsole.WriteLine(privateVariable);
// OKConsole.WriteLine(publicVariable);
// OKConsole.WriteLine(protectedVariable);
// OKConsole.WriteLine(internalVariable);
// OKConsole.WriteLine(protected_InternalVariable);}}
public class SameAssemblyDerivedClass : SameAssemblyBaseClass{public void test(){SameAssemblyDerivedClass p = new SameAssemblyDerivedClass();
// NOT OK// Console.WriteLine(privateVariable);
// OKConsole.WriteLine(p.publicVariable);
// OKConsole.WriteLine(p.protectedVariable);
// OKConsole.WriteLine(p.internalVariable);
// OKConsole.WriteLine(p.protected_InternalVariable);}}
public class SameAssemblyDifferentClass{public SameAssemblyDifferentClass(){SameAssemblyBaseClass p = new SameAssemblyBaseClass();
// OKConsole.WriteLine(p.publicVariable);
// OKConsole.WriteLine(p.internalVariable);
// NOT OK// Console.WriteLine(privateVariable);
// Error : 'ClassLibrary1.SameAssemblyBaseClass.protectedVariable' is inaccessible due to its protection level//Console.WriteLine(p.protectedVariable);
// OKConsole.WriteLine(p.protected_InternalVariable);}}}
using System;using ClassLibrary1;namespace ConsoleApplication4
{class DifferentAssemblyClass{public DifferentAssemblyClass(){SameAssemblyBaseClass p = new SameAssemblyBaseClass();
// NOT OK// Console.WriteLine(p.privateVariable);
// NOT OK// Console.WriteLine(p.internalVariable);
// OKConsole.WriteLine(p.publicVariable);
// Error : 'ClassLibrary1.SameAssemblyBaseClass.protectedVariable' is inaccessible due to its protection level// Console.WriteLine(p.protectedVariable);
// Error : 'ClassLibrary1.SameAssemblyBaseClass.protected_InternalVariable' is inaccessible due to its protection level// Console.WriteLine(p.protected_InternalVariable);}}
class DifferentAssemblyDerivedClass : SameAssemblyBaseClass{static void Main(string[] args){DifferentAssemblyDerivedClass p = new DifferentAssemblyDerivedClass();
// NOT OK// Console.WriteLine(p.privateVariable);
// NOT OK//Console.WriteLine(p.internalVariable);
// OKConsole.WriteLine(p.publicVariable);
// OKConsole.WriteLine(p.protectedVariable);
// OKConsole.WriteLine(p.protected_InternalVariable);
SameAssemblyDerivedClass dd = new SameAssemblyDerivedClass();dd.test();}}}
// In File1.cs:file interface IWidget{int ProvideAnswer();}
file class HiddenWidget{public int Work() => 42;}
public class Widget : IWidget{public int ProvideAnswer(){var worker = new HiddenWidget();return worker.Work();}}