Загрузка...

C# - Part 50 - Access Modifiers | Private | Public | Protected - Tutorial For Beginners

In C#, access modifiers are keywords that define the accessibility of a class, struct, interface, or their members (fields, methods, properties) within your program. They essentially control who can use these elements and enforce a concept called encapsulation.

Here's a breakdown of the different access modifiers:

Public: Members declared as public are accessible from anywhere in your program, regardless of the namespace or assembly. This is typically used for classes, interfaces, methods, and properties that you want to be widely used by other parts of your code.

Private: Private members are only accessible within the class or struct they are declared in. This is useful for encapsulating data and functionality that should be hidden from external code and only used internally by the class.

Protected: Protected members are accessible from the containing class and any classes that inherit from it. This allows derived classes to access and potentially override inherited members.

Internal: Internal members are accessible only from within the same assembly (a compiled unit containing your program's code). This is useful for code that should be shared within a specific project or library but not exposed externally.

protected internal (C# 6 and later): This combines protected and internal access. Members with this modifier are accessible from within the containing class, derived classes (even from different assemblies), and other classes within the same assembly.

private protected (C# 7.2 and later): This combines private and protected internal access. Members with this modifier are only accessible from within the containing class and derived classes within the same assembly.

Видео C# - Part 50 - Access Modifiers | Private | Public | Protected - Tutorial For Beginners канала parvesh
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять