C# 中,一般要叫用某個 method ,都是要先new 出來一個 instance
然後才可以去呼叫。
不過,如果你的 class 中的method 是定義為 static
在呼叫過程中,就可以不用實例化,直接可以呼叫。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
test.show();
Console.ReadLine();
}
}
class test
{
public static int a = 1;
public test()
{
a++;
}
public static void show()
{
Console.WriteLine(a);
}
}
}