Posts

Showing posts from February, 2016

Pointer in C#, use of unsafe keyword

In this article, we will understand the concept of pointers in C# and how we can use it in our C# code. While learning, I heard that C# does not support pointer which is not exactly true. It does support pointers but we do not have full control over it as in C++. Basically, to maintain type safety and security, C# does not support pointers but by explicit changes we can work with C# pointers. Use of 'unsafe' keyword By using ‘unsafe’ keyword, you can perform an operation that deals with pointers. Code or method used ‘unsafe’ modifier does not mean it is not safe but it is not verifiable by CLR. Unsafe code blocks are not dangerous but its safety does not verified by CLR, means if you are using pointers it is your responsibility to handle security risks and pointer errors. Unsafe keyword can be used with- methods, types or code blocks. Use of ‘unsafe’ keyword introduced security risks, as these are not handled by CLR and it is developer’s responsibility to manage al