C# 中內部類變數的作用域是什麼?
使用 internal 訪問說明符設定內部變數。
internal double length; internal double width;
可以在成員定義所在的應用程式中定義的任何類或方法中訪問具有 internal 訪問說明符的任何成員。
示例
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP