Pointers In C#
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();
}
}




31. Jan, 2006 by 







No comments yet... Be the first to leave a reply!