初始化--代码

 public class A
    {
       public static int X;   //1
        static A()
        {
            X = B.Y + 1;    //2 找B.Y时就会执行Y=A.X+1;
        }
    }
    public class B
    {
        public  static int Y = A.X + 1;
        static B()
        {

        }
    }

调用A.X  B.Y,调用时,几乎同时执行类内部的静态数据成员,结果X=0,Y=1,再调用静态构造函数,X=2

A.X=2,B.Y=1;

 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 MyTest("a5");
        }
    }

    public class BaseB : BaseA
    {
        public static MyTest b1 = new MyTest("b1");

        public MyTest b2 = new MyTest("b2");

        static BaseB()
        {
            MyTest b3 = new MyTest("b3");
        }

        public BaseB()
        {
            MyTest b4 = new MyTest("b4");
        }

        public new void MyFun()
        {
            MyTest b5 = new MyTest("b5");
        }
    }

    static class Program
    {
        static void Main()
        {
            BaseB baseb = new BaseB();
            baseb.MyFun();
            Console.Read();
        }
    }

    public class MyTest
    {
        public MyTest(string info)
        {
            Console.WriteLine(info);
        }
    }

 http://www.cnblogs.com/hkncd/archive/2011/06/05/2073404.html

 字符串反转(不能用string,考的就是StringBuilder)

 public static string Reverse(string str)
        {
            if (string.IsNullOrEmpty(str))
            { 
                throw new ArgumentException("参数不合法");
            }
            StringBuilder sb = new StringBuilder(str.Length);
            for (int index = str.Length - 1; index >= 0; index--)
            {
                sb.Append(str[index]);
            }
            return sb.ToString();
        }

 

public class Hong<T> 
{
    public static int count = 0;
    public Hong() 
    {
        count++;
    }
    public int GetCount()
    {
        return count;
    }
}

            new Hong<string>();
            new Hong<string>();
            new Hong<string>();
            new Hong<bool>();
            Hong<bool> h = new Hong<bool>();
            var a = h.GetCount();//2

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值