C# Language Specification


Access to private and protected members of the containing type



Download 0,75 Mb.
bet348/524
Sana06.01.2022
Hajmi0,75 Mb.
#324842
1   ...   344   345   346   347   348   349   350   351   ...   524
Bog'liq
CSharp Language Specification

Access to private and protected members of the containing type


A nested type has access to all of the members that are accessible to its containing type, including members of the containing type that have private and protected declared accessibility. The example

using System;

class C
{
private static void F() {
Console.WriteLine("C.F");
}

public class Nested


{
public static void G() {
F();
}
}
}

class Test


{
static void Main() {
C.Nested.G();
}
}

shows a class C that contains a nested class Nested. Within Nested, the method G calls the static method F defined in C, and F has private declared accessibility.

A nested type also may access protected members defined in a base type of its containing type. In the example

using System;

class Base
{
protected void F() {
Console.WriteLine("Base.F");
}
}

class Derived: Base


{
public class Nested
{
public void G() {
Derived d = new Derived();
d.F(); // ok
}
}
}

class Test


{
static void Main() {
Derived.Nested n = new Derived.Nested();
n.G();
}
}

the nested class Derived.Nested accesses the protected method F defined in Derived’s base class, Base, by calling through an instance of Derived.



        1. Download 0,75 Mb.

          Do'stlaringiz bilan baham:
1   ...   344   345   346   347   348   349   350   351   ...   524




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish