我们为什么要在 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