Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ReadInt32 Method
Collapse the table of content
Expand the table of content

Marshal.ReadInt32 Method

Reads a 32-bit signed integer from unmanaged memory.

Overload List

Reads a 32-bit signed integer from unmanaged memory.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ReadInt32(IntPtr) As Integer
[C#] public static int ReadInt32(IntPtr);
[C++] public: static int ReadInt32(IntPtr);
[JScript] public static function ReadInt32(IntPtr) : int;

Reads a 32-bit signed integer from unmanaged memory.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ReadInt32(IntPtr, Integer) As Integer
[C#] public static int ReadInt32(IntPtr, int);
[C++] public: static int ReadInt32(IntPtr, int);
[JScript] public static function ReadInt32(IntPtr, int) : int;

Reads a 32-bit signed integer from unmanaged memory.

[Visual Basic] Overloads Public Shared Function ReadInt32(Object, Integer) As Integer
[C#] public static int ReadInt32(object, int);
[C++] public: static int ReadInt32(Object, int);
[JScript] public static function ReadInt32(Object, int) : int;

Example

[Visual Basic, C#] The following example compares two ways of interacting with an unmanaged C-style Int32 array. The ReadInt32 method provides direct access to the array's element values.

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of ReadInt32. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim unmanagedArray As IntPtr = ...
Dim i As Integer
' One way to print the 10 elements of the C-style unmanagedArray
Dim newArray As Int32(9)
Marshal.Copy(unmanagedArray, newArray, 0, 10)
For i = 0 To newArray.Length
  Console.WriteLine(newArray(i))
Next i
' Another way to print the 10 elements of the C-style unmanagedArray
For i = 0 To 10
  Console.WriteLine(Marshal.ReadInt32(unmanagedArray, i))
Next i
   
[C#] 
IntPtr unmanagedArray = ...;
// One way to print the 10 elements of the C-style unmanagedArray
byte [] newArray = new Int32[10];
Marshal.Copy(unmanagedArray, newArray, 0, 10);
for (int i = 0; i < newArray.Length; i++)
  Console.WriteLine(newArray[i]);
// Another way to print the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
  Console.WriteLine(Marshal.ReadInt32(unmanagedArray, i));
   

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Marshal Class | Marshal Members | System.Runtime.InteropServices Namespace

Show:
© 2015 Microsoft