7.7. Unsafe Code

The core C# language differs notably from C and C++ in its omission of pointers as a first-class data type. Instead, C# provides references and the ability to create objects that are managed by a garbage collector. This design, coupled with other features, makes C# a much safer language than C or C++. In the core C# language it is simply not possible to have an uninitialized variable, a “dangling” pointer, or an expression that indexes an array beyond its bounds.

However, even though it is possible to model everything as references, sometimes you need pointer operations. For example, interfacing with the underlying operating system and coding certain performance-critical operations require raw pointer manipulation. Java does ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.