Agn*_*ian 2 c# arrays array-initialize
我需要在C#程序中对一系列点进行硬编码.C风格的初始化程序不起作用.
PointF[] points = new PointF{
/* what goes here? */
};
Run Code Online (Sandbox Code Playgroud)
怎么做?
像这样:
PointF[] points = new PointF[]{
new PointF(0,0), new PointF(1,1)
};
Run Code Online (Sandbox Code Playgroud)
在c#3.0中,你可以写得更短:
PointF[] points = {
new PointF(0,0), new PointF(1,1)
};
Run Code Online (Sandbox Code Playgroud)
更新 Guffa指出我要用var points它来缩短,实际上不可能"用数组初始化器隐式输入变量".