C# 靜態成員與例項成員

iamzxf發表於2015-03-31


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

namespace dataOper
{
    class Counter
    {
        public int number;
        public static int count;
        public Counter()
        {
            count = count + 1;
            number = count;
        }
        public void showInstance()
        {
            Console.WriteLine(number);
            Console.WriteLine(count);
        }

        public static void ShowStatic()
        {
            //Console.WriteLine(number);
            Console.WriteLine(count);
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            Counter c1 = new Counter();
            c1.showInstance();
            Counter.ShowStatic();

            Console.WriteLine(c1.number);
            Console.WriteLine(Counter.count);

            Counter c2 = new Counter();
            c2.showInstance();
            Counter.ShowStatic();

            Console.ReadLine();
        }
    }
}



相關文章