摘要: 一、方法中的变量的作用域public static void Main(){ int j=20; for(int i=0;i<10;i++) { int j=30; ... }}出错!int j=20的作用域在整个方法体中,for循环也是它的作用域,相当于定于了两个j.二、c#将声明为类型级的变量看作是字段,而在方法体中声明的变量看做局部变量。class s{ int j=20;public static void Main(){ int j=20; for(int i=0;i<10;i++) { }}}正确!M... 阅读全文
posted @ 2011-10-07 23:49 南山砍柴的 阅读(180) 评论(0) 推荐(0)
摘要: 值类型包括:结构体,数值类型,bool型,枚举和可空类型结构体:struct(直接派生于System.ValueType); 数值类型: 整 型:sbyte(System.SByte的别名),short(System.Int16),int(System.Int32),long (System.Int64),byte(System.Byte),ushort(System.UInt16),uint (System.UInt32),ulong(System.UInt64),char(System.Char); 浮点型:float(System.Single),double(System.Double 阅读全文
posted @ 2011-10-07 23:21 南山砍柴的 阅读(162) 评论(0) 推荐(0)
摘要: using System;public class T{ public virtual void zzz() { Console.WriteLine("t.zzz()"); }}public class A:T{ public int book=6; public A() { Console.WriteLine("A"); } //虚方法 public virtual void fun() { Console.WriteLine("A.fun()"); ... 阅读全文
posted @ 2011-10-07 22:16 南山砍柴的 阅读(212) 评论(0) 推荐(0)
摘要: public class BaseA{ public static MyTest a1 = new MyTest("a1"); public MyTest a2 = new MyTest("a2"); static BaseA() { MyTest a3 = new MyTest("a3"); } public BaseA() { MyTest a4 = new MyTest("a4"); } public virtual void MyFun() { MyTest a5 = new MyTe... 阅读全文
posted @ 2011-10-07 21:00 南山砍柴的 阅读(436) 评论(0) 推荐(0)