Internal 키워드를 사용하면 내부 액세스 지정자를 설정할 수 있습니다.
내부 액세스 지정자는 클래스가 해당 멤버 변수와 멤버 함수를 현재 어셈블리의 다른 함수 및 개체에 노출할 수 있도록 합니다.
내부 액세스 지정자가 있는 모든 멤버는 해당 멤버가 정의된 응용 프로그램 내에 정의된 모든 클래스 또는 메서드에서 액세스할 수 있습니다.
예
using System;
namespace RectangleApplication {
class Rectangle {
internal double length;
internal double width;
double GetArea() {
return length * width;
}
public void Display() {
Console.WriteLine("Length: {0}", length);
Console.WriteLine("Width: {0}", width);
Console.WriteLine("Area: {0}", GetArea());
}
}
class Demo {
static void Main(string[] args) {
Rectangle rc = new Rectangle();
rc.length = 10.35;
rc.width = 8.3;
rc.Display();
Console.ReadLine();
}
}
}