繁体   English   中英

如何将这行代码从C#转换为vb.net

[英]How to convert this line of code from C# to vb.net

我正在使用http://www.developerfusion.com/tools/convert/csharp-to-vb/将代码块从C#转换为VB.NET

除了一行我无法弄清楚如何转换外,其他一切进展顺利:

C#来源

result.DrawPolyline(Array.ConvertAll<PointF, Point>(pts, Point.Round), true, new Bgr(Color.Red), 5);

使用转换器可以做到这一点

result.DrawPolyline(Array.ConvertAll(Of PointF, Point)(pts, Point.Round), True, New Bgr(Color.Red), 5)

上一行中的错误是:

未为“公共共享函数回合(值作为System.Drawing.PointF)作为System.Drawing.Point”的参数“值”指定参数。

这应该将PointF数组转换为Point:

result.DrawPolyline(Array.ConvertAll(Of PointF, Point)(pts, Function(p) Point.Round(p)), True, New Bgr(Color.Red), 5)

您需要将PointF传递给Point.Round

经过测试:

Dim pts As PointF() = {New PointF(123.23, 12345.23)}
Dim r = Array.ConvertAll(Of PointF, Point)(
            pts,
            Function(p) Point.Round(p))

如果您将委托传递给Point.Round也将Point.Round如@Jon所提到的:

Dim pts As PointF() = {New PointF(123.23, 12345.23)}
Dim r = Array.ConvertAll(Of PointF, Point)(
            pts,
            AddressOf Point.Round)

Array.ConvertAll的第二个参数应该是用于转换的方法(请参阅此处

该行可能在Point.Round调用之前丢失了AddressOf ,因此该方法将作为委托传递而不是被执行,如下所示:

result.DrawPolyline(Array.ConvertAll(Of PointF, Point)(pts, AddressOf Point.Round), True, New Bgr(Color.Red), 5)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM