C#中类的内部变量的作用域是什么?
使用内部访问说明符设置内部变量。
internal double length; internal double width;
具有内部访问说明符的任何成员都可以从定义该成员的应用程序内定义的任何类或方法中进行访问。
示例
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());
}
} //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
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短