Question C# to VB Conversion for Arrays

no1nhere

New member
Joined
Jun 15, 2023
Messages
1
Programming Experience
3-5
I am trying to use ScottPlot spline fitting and cannot seem to get the syntax right for declaring the arrays.
(double[] smoothXs, double[] smoothYs) = ScottPlot.Statistics.Interpolation.Cubic.InterpolateXY(xs, ys, 200);

This is where I cannot get the VB correct VB syntax.: (double[] smoothXs, double[] smoothYs)
Any help would be greatly appreciated.
 
This is not really about arrays but rather about tuples. You should start by reading this. C# has greater support for tuples than VB does so it may not be possible to do the same thing in VB, but I haven't used tuples much in VB so I'm not 100% sure. Here are a couple of options that will work though.

Firstly, you can declare a variable of that tuple type and use its properties, e.g.
VB.NET:
Sub Main()
    Dim t As (smoothXs As Double(), smoothYs As Double())

    t = DoSomething()

    Console.WriteLine(t.smoothXs)
    Console.WriteLine(t.smoothYs)
End Sub

Private Function DoSomething() As (Double(), Double())
    Return ({1.1, 2.2}, {3.3, 4.4})
End Function
Secondly, you can do basically the same thing, with or without naming the properties, and then declare the other two variables separately, e.g.
VB.NET:
Dim t = DoSomething()
Dim smoothXs = t.Item1
Dim smoothYs = t.Item2

Console.WriteLine(smoothXs)
Console.WriteLine(smoothYs)
The best option depends on exactly what you need to do with the data after the part you've shown us.
 
Back
Top