หากไม่มีการระบุตัวแก้ไขการเข้าถึง ค่าดีฟอลต์คือ Internal ตัวระบุการเข้าถึงภายในอนุญาตให้คลาสเปิดเผยตัวแปรสมาชิกและฟังก์ชันสมาชิกไปยังฟังก์ชันและอ็อบเจ็กต์อื่นๆ ในแอสเซมบลีปัจจุบัน กล่าวอีกนัยหนึ่ง สมาชิกใดๆ ที่มีตัวระบุการเข้าถึงภายในสามารถเข้าถึงได้จากคลาสหรือวิธีการใดๆ ที่กำหนดไว้ภายในแอปพลิเคชันที่สมาชิกถูกกำหนดไว้
ต่อไปนี้คือตัวอย่างที่แสดงการใช้งาน Internal access specifier -
ตัวอย่าง
using System;
namespace RectangleApplication {
class Rectangle {
//member variables
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());
}
}//end class Rectangle
class ExecuteRectangle {
static void Main(string[] args) {
Rectangle r = new Rectangle();
r.length = 4.5;
r.width = 3.5;
r.Display();
Console.ReadLine();
}
}
} ผลลัพธ์
Length: 4.5 Width: 3.5 Area: 15.75