I have been investigating C-style pointers in Visual Basic .NET for a while now. I have come across http://support.microsoft.com/kb/199824?wa=wsignin1.0 but I have no idea if th
There's some issues with your C code, one of them being this:
int *myNumber=3; //the * means it's a pointer
You cannot assign a value to a pointer like that, without first allocating memory to it.
So you would do the following:
int* myNumber = malloc(sizeof(int));
*myNumber = 3;
free(myNumber);
VB.NET has no notion of pointers. Everything (ie every Object
) is a reference, and that's about as close to pointers it will get without using Interop. If you need to do interop there's the IntPtr
type which can be used to represent a pointer type.
Your VB.NET program might look something like this: (forgive me if the syntax isn't exactly correct, it's been a while)
Sub Main
Dim myNumber As Integer = 3
doubleIt(myNumber)
Console.WriteLine(myNumber)
End Sub
Sub doubleIt(ByRef val As Integer)
val *= 2
End Sub