DEV Community

hdemiray
hdemiray

Posted on

C# Access Modifiers Private, Public, Internal, Protected Nedir ? / Erişim Bildirgeçleri

Bir class oluşturulduğunda bu classın default erişim belirteci internal 'dır.

Erişim Belirteçleri : Public, Internal, Protected, Private

Internal: Proje namespace'inden harici bir alanda referans verilse dahi kullanılamaz. Aynı assembly içinde geçerli demektir.

Public: Referans verildiği heryerde kullanılabilir. Farklı assemblylerde fieldd property yada classlarını kullanabilir.

En üst seviyeli bir class public veya internal olarak kullanılmak zorundadır.
Private veya protected olarak yalnızca başka bir classın içerisinde tanımlanabilir.

Private: Private sadece bir üst blokta geçerlidir(kıvırcık parantez). Ve inherit edildiği yerde kullanılamaz.

public class MyClass()
{
    class MyOtherClass()
    {
        //buradan alttaki değişkene erişemeyiz.
    }
    private MyPrivateClass()
    {
        //bu class yalnızca üst classta kullanılabilir.
        private int num=1;
    }
}
Enter fullscreen mode Exit fullscreen mode

Bir field'ın default belirteci private'dır. Örn: int num=1; private bir değişkendir.

Protected: Private ile aynı özellikleri taşır bir üst parantezde çalışır onun haricinde inherit edildiği yerde de erişilebilir. Ancak private inherit edildiği yerde erişilemez.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay