Chapter 30. Unsafe Code and PInvoke

In This Chapter

  • Unsafe Code

  • Platform Invoke

An important consideration in any project is reuse of existing code. The ability to access legacy code containing business logic or low-level system functionality could lead to significant benefits in time and cost. To meet this demand, C# provides a mechanism to access legacy systems, with a feature known as PInvoke, short for Platform Invoke.

Unsafe code permits a block of code to use pointers, low-level types that allow indirect access to memory and other types. This opens new opportunities for optimization and interfaces to operating system or legacy code that requires pointers. The primary reason for unsafe code blocks is to separate safe C# code from pointer-related ...

Get C# Unleashed 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.