作为一个相对新手,我尝试尽可能多地阅读特定主题并尽可能多地测试/编写代码。我正在查看Jons Brainteasers之一(问题 #2),我的输出与答案不同。这让我来这里询问最近的版本是否发生了变化,并查看其他人从这段代码中得到了什么输出。
问题是,“将展示什么,为什么,以及你有多自信?”
using System;
class Foo
{
static Foo()
{
Console.WriteLine ("Foo");
}
}
class Bar
{
static int i = Init();
static int Init()
{
Console.WriteLine("Bar");
return 0;
}
}
class Test
{
static void Main()
{
Foo f = new Foo();
Bar b = new Bar();
}
}
如果有的话,什么会导致我们得到两个不同的答案?