我很惭愧,这是在C#中完成的最基本的任务,我似乎无法弄清楚。是的,我可以编译它并使其运行,但是我想对它进行剖析并逐字理解它。C#基础理解问题
using System; *//"include standard System classes"*
namespace DataTypeApplication *//"Create new classes within DataTypeApp..."*
{
class Program *//"Name this class "Program""*
{
static void Main(string[] args) *//Declares the main function of this class?*
{
Console.WriteLine("Size of int: {0}", sizeof(int)); *//Print string using sizeof(int)*
Console.ReadLine(); *//Irrelevant*
}
}
}
我很困惑,为什么会这样运行。程序已创建但未被调用。而且,这会为int输出4,但是这4个来自哪里呢?
我很感谢任何帮助理解这一点,但也许C#只是不适合我。 -_-
“int”是“In32”,意思是32位是4字节。 –
'sizeof(int)'返回4个字节的int类型的大小。这是为字符串中的“{0}”占位符插入的。 “ReadLine”要求用户输入,并且是一种让程序保持活动状态直到读取完整输出的方式。其余是正确的。 – poke
查看项目属性,你会看到“Program.Main”是“入口点”的位置 – DaveShaw