Export (0) Print
Expand All

Marshal.Copy Method (Int16[], Int32, IntPtr, Int32)

.NET Framework 1.1

Copies data from a one-dimensional, managed 16-bit signed integer array to an unmanaged memory pointer.

[Visual Basic]
Overloads Public Shared Sub Copy( _
   ByVal source() As Short, _
   ByVal startIndex As Integer, _
   ByVal destination As IntPtr, _
   ByVal length As Integer _
)
[C#]
public static void Copy(
 short[] source,
 int startIndex,
 IntPtr destination,
 int length
);
[C++]
public: static void Copy(
 short source __gc[],
 int startIndex,
 IntPtr destination,
 int length
);
[JScript]
public static function Copy(
   source : Int16[],
 startIndex : int,
 destination : IntPtr,
 length : int
);

Parameters

source
The one-dimensional array to copy from.
startIndex
The zero-based index into the array where Copy should start.
destination
The memory pointer to copy to.
length
The number of array elements to copy.

Exceptions

Exception Type Condition
ArgumentOutOfRangeException startIndex and length are not valid.

Remarks

You can use this method to copy a subset of a one-dimensional, .NET-based array to an unmanaged C-style array.

Note   This method uses SecurityAction.LinkDemand to prevent it from being called from untrusted code; only the immediate caller is required to have SecurityPermissionAttribute.UnmanagedCode permission. If your code can be called from partially trusted code, do not pass user input to Marshal class methods without validation. For important limitations on using the LinkDemand member, see Demand vs. LinkDemand.

Example

[Visual Basic, C#] The following example demonstrates how to copy a one-dimensional array to an unmanaged memory pointer.

[Visual Basic] 
Public Overloads Shared Sub Copy(source As Short(), _
  startIndex As Integer, destination As IntPtr, length As Integer)
      
[C#] 
public static void Copy(short[] source, int startIndex, 
  IntPtr destination, int length);
      

[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.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

.NET Framework Security: 

See Also

Marshal Class | Marshal Members | System.Runtime.InteropServices Namespace | Marshal.Copy Overload List

Show:
© 2014 Microsoft