摘要: readonly:可以在字段上使用的修饰符,当字段声明包括 readonly 修饰符时,该声明引入的字段赋值只能作为声明的一部分出现,或者出现在同一类的构造函数中。可以使用如下方法赋值:View Code // cs_readonly_keyword.cs// Readonly fieldsusing System;public class ReadOnlyTest{ class SampleClass { public int x; // Initialize a readonly field public readonly int y = 25; public readonly int z 阅读全文
posted @ 2011-03-29 10:52 [曾恩] 阅读(324) 评论(0) 推荐(0) 编辑
摘要: this:引用类的当前实例;由于静态成员函数存在于类一级,并且不是对象的一部分,因此没有 this 指针,在静态方法中引用 this 是错误的;它的用法分以下几种情况:1. 限定被相似的名称隐藏的成员public Employee(string name, string alias) { this.name = name; this.alias = alias;} 2. 将对象作为参数传递到其他方法CalcTax(this);3. 声明索引器public int this [int param]{ get { return array[param]; } set { array[param] 阅读全文
posted @ 2011-03-29 10:16 [曾恩] 阅读(305) 评论(2) 推荐(0) 编辑
摘要: params:指定在参数数目可变处采用参数的方法参数;它后面不允许任何其它参数,并且只允许有一个params参数。params// cs_params.csusing System;public class MyClass { public static void UseParams(params int[] list) { for (int i = 0 ; i < list.Length; i++) { Console.WriteLine(list[i]); } Console.WriteLine(); } public static void UseParams2(params ob 阅读全文
posted @ 2011-03-29 10:03 [曾恩] 阅读(287) 评论(0) 推荐(0) 编辑