簡體   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