CType
is a cast operator/function, so comparable to (SERVER_INFO_100) object
in C#.
ServerInfo = (SERVER_INFO_100) System.Runtime.InteropServices.Marshal.PtrToStructure(BufferPtr, GetType(SERVER_INFO_100));
The closest you get to the C# cast operator is DirectCast
in VB.NET. Read:
Difference between DirectCast() and CType() in VB.NET
In C# you could also use the as
cast operator which is the same as the VB.NET TryCast
.
ServerInfo = System.Runtime.InteropServices.Marshal.PtrToStructure(BufferPtr, GetType(SERVER_INFO_100)) as SERVER_INFO_100;
This has the advantage that you don't get an exception if the type is not SERVER_INFO_100
.
Please suggest how to do this and also forloop
The for-loop is explained in the docs.