更新时间:2023-01-13 08:36:29
在.Net中,不同的代码语法生成相同的代码.
考虑下面的两位代码:
In .Net different code syntax produces identical code.
Consider the two bits of code below:
private string myString;
public string MyString
{
get
{
return myString;
}
set
{
myString = value;
}
}
和
and
public string MyString {get; set;}
他们俩都做完全一样的事情
第二个块基本上只是创建第一个块的简便方法.
对于第二个Array示例,C#编译器知道"您要创建一个新的int[]
并在后台为您完成.
这只是使编码人员的工作更轻松的最新方法.
They both do exactly the same thing
The second block is basically just a shorthand way to create the first.
For your second Array example the C# compiler ''knows'' that you want to create a new int[]
and does it for you behind the scenes.
It is just a more recent way to do it to make the coders job easier.
据我所知,没有什么区别.
它们只是声明和实例化数组的两种不同方式.我怀疑在幕后产生的IL代码会是相同的.
As far as I know, there is no difference.
They are just two different ways to declare and instantiate Arrays. I suspect that behind the scenes the IL code produced would be the same.