1

In one C# maintenance project I came across following variable declaration:

Int32* iProgressAddress;

Is it pointer declaration in C#?

I thought that there is no pointer concept in C#, what does that statement mean?

Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
Prashant Cholachagudda
  • 13,012
  • 23
  • 97
  • 162
  • 1
    See also these questions: http://stackoverflow.com/questions/430112/what-is-the-difference-between-a-c-reference-and-a-pointer http://stackoverflow.com/questions/584134/should-you-use-pointers-unsafe-code-in-c http://stackoverflow.com/questions/607159/c-benefit-of-explicitly-stating-unsafe-compiler-option – Daniel Daranas Jun 12 '09 at 09:11
  • Here's a nice intro to pointers in C#- http://www.codeproject.com/KB/cs/csunsafeintro01.aspx – RichardOD Jun 12 '09 at 09:19

3 Answers3

5

C# does support pointers, but it's limited to pointing to primitive data types that are unmanaged types, such as ints, floats, enums, and other pointer types (plus the rest of the primitives).

edit: as well as value types

Sev
  • 15,401
  • 9
  • 56
  • 75
  • Not quite correct. You can have pointers to all *value types*, including structs, not just primitives. But only structs that don't contain reference type variables. – JulianR Jun 12 '09 at 12:19
3

Yes, it is.

Notice, that the method is marked unsafe. As well as the assembly.

There is a lot of things to know before using pointers from the managed code. For instance, pointer pinning.

bohdan_trotsenko
  • 5,167
  • 3
  • 43
  • 70
1

I'm sorry, I'm afraid that's a pointer, and you have to get used to it.

REALLY! Pointers aren't that scary. :)

SuPra
  • 8,488
  • 4
  • 37
  • 30