我們為什麼要在 C# 中使用 internal 關鍵字?
透過 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();
}
}
}
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP