Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharpNotesForProfessionals.pdf
Скачиваний:
57
Добавлен:
20.05.2023
Размер:
6.12 Mб
Скачать

}

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")]

Section 40.6: protected

The protected keyword marks field, methods properties and nested classes for use inside the same class and derived classes only:

public class Foo()

{

protected void SomeFooMethod()

{

//do something

}

protected class Thing

{

private string blah; public int N { get; set; }

}

}

public class Bar() : Foo

{

private void someBarMethod()

{

SomeFooMethod(); // inside derived class

var thing = new Thing(); // can use nested class

}

}

public class Baz()

{

private void someBazMethod()

{

var foo = new Foo();

foo.SomeFooMethod(); //not accessible due to protected modifier

}

}

GoalKicker.com – C# Notes for Professionals

166