类初始化成员加载测试
public class SS
{
public static int ss = getNum();
public static int age = 23;
private static int getNum()
{
return age;
}
}
public class KK
{
public KK()
{
Console.WriteLine("55555");
wsd = 66666;
}
private static string fds = null;
public static string FDS
{
get
{
return fds = MSS.Dof();
}
}
public int wsd;
public static int ddddddds()
{
Console.WriteLine("1111111");
return 77777;
}
}
public class MSS
{
public static int dd = KK.ddddddds();
public static string Dof()
{
Console.WriteLine("33333");
return "444444";
}
}
class Program
{
static void Main(string[] args)
{
Test();
Console.Read();
}
public static void Test()
{
Console.WriteLine("222222");
Console.WriteLine(KK.FDS);
Console.WriteLine(new KK().wsd);
Console.WriteLine(MSS.dd);
Console.WriteLine(SS.ss);
//Console.WriteLine("33333");
//int kkk = KK.fds;
//int hhh = new KK().wsd;
//int ppp = MSS.dd;
//Console.WriteLine(kkk);
//Console.WriteLine(hhh);
//Console.WriteLine(ppp);
}
}
这是第一个
public class FOO
{
② //static FOO()
//{
//}
public static string x3 = GetString3("11111");
public static string GetString3(string s)
{
Console.WriteLine(s);
return s;
}
public static string x = GetString("22222");
public static string GetString(string s)
{
Console.WriteLine(s);
return s;
}
public static string x2 = GetString2("33333");
public static string GetString2(string s)
{
Console.WriteLine(s);
return s;
}
}
public class dsds
{
static void Main(string[] args)
{
Console.WriteLine("44444");
FOO.GetString("5555555");
① string field = FOO.x;
Console.Read();
}
}
把①和②分别注释和放开 输出的差别