阅读量:100
- 在类中声明public方法或属性,可以在其他类中访问该方法或属性。
public class MyClass
{
public void MyMethod()
{
// 执行一些操作
}
public int MyProperty { get; set; }
}
- 在接口中使用public关键字,表示接口的成员对外公开。
public interface IMyInterface
{
void MyMethod();
}
- 在结构体中使用public关键字,表示结构体的成员对外公开。
public struct MyStruct
{
public int MyProperty;
}
- 在命名空间中使用public关键字,表示命名空间对外公开。
namespace MyNamespace
{
public class MyClass
{
// 类的定义
}
}
- 在程序集中使用public关键字,表示程序集对其他程序集可见。
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("MyOtherAssembly")]