静态类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    //静态类和普通类的区别
    //静态类不能被实例化
    //正常的类
    class A
    {
        internal void M()
        {
            Console.WriteLine("M() of class A");
        }
    }

    //静态类
    class S
    {
        internal static void StaticMethod()
        {

            Console.WriteLine("StaticMethod() of class S");
        }
        internal void nonStaticMethod()
        {
            Console.WriteLine("nonStaticMethod() of class S");
        }

    }
    class Program
    {
        static void Main()
        {
            A a = new A();
            a.M();
            ////Type obj = new Type();
            S s = new S();
            s.nonStaticMethod();
            //error静态类不能被实例化
            S.StaticMethod();
            Console.Read();
        }
    }
}

posted @ 2012-05-07 18:01  |▍花舞花落泪 ╮  阅读(92)  评论(0编辑  收藏  举报