Search Forum
(53671 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


 
Printable Version

Pointers In C#
By Sankar Ramanathan

Here is a simple example of how to use pointers using C#. It is short and easy to follow.


//Compilation
//CSC FileName.CS

using System;

class Test
{
 unsafe static void WriteLocations() 
 {
  int *p;
  int i;
  i = 10;
  p = &i;


  string addr;
  addr = int.Format((int) p, "X");
  //To Format the Pointer to a String

  Console.WriteLine(addr);
  Console.WriteLine(*p);

  *p = 333;
  Console.WriteLine(i);
  //Change the Value using Pointer

  i = *(&i) + 10;
  Console.WriteLine(i);

 }

 static void Main() 
 {
  WriteLocations();
 }
}