Export (0) Print
Expand All

Unsafe Code Sample

This sample demonstrates how to use unmanaged code (code using pointers) in C#.

This sample contains the source code for the Unsafe Code Tutorial.

Building and Running the Sample Within Visual Studio

To build and run the Unsafe Code samples

  1. Open the solution (Unsafe.sln).
  2. In Solution Explorer, right-click the FastCopy project and click Set as StartUp Project.
  3. From the Debug menu, click Start Without Debugging.
  4. In Solution Explorer, right-click the ReadFile project and click Set as StartUp Project.
  5. In Solution Explorer, right-click the ReadFile project and click Properties.
  6. Open the Configuration Properties folder and click Debugging.
  7. In the Command Line Arguments property, enter ..\..\ReadFile.cs.
  8. Click OK.
  9. From the Debug menu, click Start Without Debugging.
  10. In Solution Explorer, right-click the PrintVersion project and click Set as StartUp Project.
  11. From the Debug menu, click Start Without Debugging.

Building and Running the Sample from the Command Line

To build and run the Unsafe Code samples

  1. Use the Change Directory command to change to the Unsafe directory.
  2. Type the following:
    cd FastCopy
    csc FastCopy.cs /unsafe
    FastCopy
    
  3. Type the following:
    cd ..\ReadFile
    csc ReadFile.cs /unsafe
    ReadFile ReadFile.cs
    
  4. Type the following:
    cd ..\PrintVersion
    csc PrintVersion.cs /unsafe
    PrintVersion
    

See Also

Unsafe Code Tutorial | Tutorial Samples

Show:
© 2014 Microsoft