Unsafe code in C#
In general, the code written in C# is safe code that doesn`t directly access memory using pointers. It also doesn’t allocate raw memory. Instead, managed objects are created.
On the other hand, unsafe code in C# usually refers to a section of code that is not processed by the CLR (Common Language Runtime) and directly access memory using pointers.
Since pointers are complex and might result in memory-related errors like stack overflow, overwritten system memory, etc., extra caution must be taken while handling unsafe code.
By default, pointers are not supported in C#. However, the use of pointer variables is permitted by the unsafe keyword.