Введение в программирование

       

public static int myPublicInt; internal


using System; namespace MyNameSpace { public class A { public static int myPublicInt; internal static int myInternalInt; private static int myPrivateInt = 0;

public class Nest1 // "Вложенный" член класса { public static int myPublicInt; internal static int myInternalInt; private static int myPrivateInt = 0; }

private class Nest2 // "Вложенный" член класса { public static int myPublicInt = 0; internal static int myInternalInt = 0; private static int myPrivateInt = 0; } } public class MyClass { public static int Main() { // Доступ к членам класса A: A.myPublicInt = 1; // Доступ не ограничен A.myInternalInt = 2; // Только в текущем проекте // A.myPrivateInt = 3; - ошибка: нет // доступа вне класса // Доступ к членам класса Nest1: A.Nest1.myPublicInt = 1; // Доступ не ограничен A.Nest1.myInternalInt = 2; // Только в текущем проекте // A.Nest1.myPrivateInt = 3; - ошибка: нет // доступа вне класса Nest1 // Доступ к членам класса Nest2: // A.Nest2.myPublicInt = 1; - ошибка: нет // доступа вне класса A // A.Nest2.myInternalInt = 2; - ошибка: нет // доступа вне класса A // A.Nest2.myPrivateInt = 3; - ошибка: нет // доступа вне класса Nest2 return 0; } } }

Листинг 15.1.
Закрыть окно





using System;

namespace MyNameSpace

{

public class A

{

public static int myPublicInt;



internal static int myInternalInt;

private static int myPrivateInt = 0;

public class Nest1 // "Вложенный" член класса

{

public static int myPublicInt;

internal static int myInternalInt;

private static int myPrivateInt = 0;

}

private class Nest2 // "Вложенный" член класса

{

public static int myPublicInt = 0;

internal static int myInternalInt = 0;

private static int myPrivateInt = 0;

}

}

public class MyClass

{

public static int Main()

{

// Доступ к членам класса A:

A.myPublicInt = 1; // Доступ не ограничен

A.myInternalInt = 2; // Только в текущем проекте

// A.myPrivateInt = 3; - ошибка: нет

// доступа вне класса

// Доступ к членам класса Nest1:

A.Nest1.myPublicInt = 1; // Доступ не ограничен

A.Nest1.myInternalInt = 2; // Только в текущем проекте

// A.Nest1.myPrivateInt = 3; - ошибка: нет

// доступа вне класса Nest1

// Доступ к членам класса Nest2:

// A.Nest2.myPublicInt = 1; - ошибка: нет

// доступа вне класса A

// A.Nest2.myInternalInt = 2; - ошибка: нет

// доступа вне класса A

// A.Nest2.myPrivateInt = 3; - ошибка: нет

// доступа вне класса Nest2

return 0;

}

}

}


Содержание раздела