vb.netpointersaddress-operator

VB.NET: Pointer and Address Operator from C / Convert C to VB.NET


double *dDevTabPressure;
static double sPT_Mach;
dDevTabPressure = &sPT_Mach;

I want to convert this C-code to VB.NET-code. Unfortunatly there are no pointer and adress operator in VB.NET Do you have a simple soloution?


Solution

  • While VB.NET doesn't have pointers, you can use an object to wrap the Double. Object assignments (=) are by reference instead of by value like simple data types.

    For example, this sample code wraps the double into an anonymous object. This when the value is updated in one object, its updated in the other because the object points to the same location in memory.

        Dim devTabPressure = New With {.Value = Convert.ToDouble(2)}
        Dim devTabPressure2 = devTabPressure
        devTabPressure.Value = 5
    
        Console.WriteLine(devTabPressure.Value) ' Writes a 5
        Console.WriteLine(devTabPressure2.Value)  ' ALSO Writes a 5
        Console.Read()