Mega Code Archive

 
Categories / C# / Language Basics
 

Demonstrate pointers and unsafe

/* C#: The Complete Reference  by Herbert Schildt  Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // Demonstrate pointers and unsafe.    using System;    public class UnsafeCode {    // mark Main as unsafe    unsafe public static void Main() {      int count = 99;      int* p; // create an int pointer        p = &count; // put address of count into p        Console.WriteLine("Initial value of count is " + *p);        *p = 10; // assign the to count via p            Console.WriteLine("New value of count is " + *p);    }  }