Why is it a bad idea to use C# pointers?

written by Ryan Olshan on Wednesday, December 07 2005

I just answered a post on one of the lists I am a member of that asked how to use pointers in C#. Using pointers in C# is a very bad idea. Pointers reference a location in memory. If the garbage collector is called, the location of an object in memory could be moved and the end result is obvious. As such, pointers are categorized as unsafe.

On a side note, any unsafe code in C#, such as pointers, must use the unsafe modifier keyword:

unsafe int * ptr;

R
Kick this post on .NET Kicks

Similar Posts

  1. Getting the content of a GridView cell on edit
  2. GridView Dynamic Button Frustrations
  3. Generic ExecuteScalar method

Post a comment