gpt4 book ai didi

C#:PointF() 数组初始化器

转载 作者:行者123 更新时间:2023-11-30 19:22:46 24 4
gpt4 key购买 nike

我需要在我的 C# 程序中对一组点进行硬编码。 C 风格的初始化程序不起作用。

PointF[] points = new PointF{
/* what goes here? */
};

它是怎么做到的?

最佳答案

像这样:

PointF[] points = new PointF[]{
new PointF(0,0), new PointF(1,1)
};

在 c# 3.0 中你可以写得更短:

PointF[] points = {
new PointF(0,0), new PointF(1,1)
};

更新 Guffa 指出我用var points 来缩短,确实不可能“使用数组初始值设定项隐式类型化变量”。

关于C#:PointF() 数组初始化器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/625690/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com