数组中的新关键字 [英] key word new in array
本文介绍了数组中的新关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
有什么区别
int []x=new int[]{1,2,3};
和
int[]x={1,2,3};
Thnx提供任何帮助
Hi everyone,
What a difference between
int []x=new int[]{1,2,3};
and
int[]x={1,2,3};
Thnx for any help
推荐答案
在.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.
这篇关于数组中的新关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文