Msdn:搜索access modifiers ?Class and Struct Accessibility Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified. Class and Struct Member Accessibility Class members (including nested classes and structs) can be declared with any of the five types of access. Struct members cannot be declared as protected because structs do not support inheritance. public The type or member can be accessed by any other code in the same assembly or another assembly that references it. private The type or member can be accessed only by code in the same class or struct. protected The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class. internal The type or member can be accessed by any code in the same assembly, but not from another assembly. protected internal The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type. 给定一个数组,要求返回数组的最大值和最大值首次出现的索引值。 public int MaxValue(int[] array, out int maxIndex) { } public class Test { public void Method(out int i) { i = 10; } static void Main() { Test t = new Test(); int j; t.Method(out j); Console.WriteLine(j); } } 就是说,静态方法中的字段必须是静态字段,因为静态方法是类的行为,所以里面的字段也必须是属于类的行为。不可以属于某个具体的对象。 使用 static 修饰符声明属于类型本身而不是属于特定对象的静态成员。static 修饰符可用于类、字段、方法、属性、运算符、事件和构造函数,但不能用于索引器、析构函数或类以外的类型。例如,下面的类声明为 static,并且只包含 static 方法: static class CompanyEmployee { public static string GetCompanyName(string name) {
您可能关注的文档
最近下载
- 数字图像处理图像编码.ppt VIP
- 湖北城市建设职业职业技术学院2025年高职单招考试城市燃气工程技术专业考试大纲.pdf VIP
- 长帝电烤箱TV42W使用说明书用户手册.pdf
- 气象学与气候学课件.pptx
- 电子科技大学《光电图像处理》 第六章 图像编码与压缩 ppt课件.pptx VIP
- 对外经济贸易大学2021-2022学年《Python程序设计》期末考试试卷(A卷)及标准答案.docx
- 高考数学极值点偏移练习题(含答案).docx VIP
- 化工过程安全管理导则-装置安全规划与设计课件.pptx VIP
- 五脏与情志 jt叔叔 JT叔叔伤寒杂病论慢慢教(.)五脏与情志.doc VIP
- 图像处理与分析图像的编码技术.ppt VIP
原创力文档

文档评论(0)