What is the use of unsafe keyword in C#?
Answer:
In C# the value can be directly referenced to a variable, so there is no need of pointer.
Use of pointer sometime crashes the application. But C# supports pointer, that means we can use pointer in C#.
The use of pointer in C# is defined as a unsafe code.
So if we want to use pointer in C# the pointer must be present in the body of unsafe declaration.
But pointer does not come under garbage collection.
Example:-
unsafe
{
int a, *b;
a = 25;
b = &a;
Console.WriteLine("b= {0}",b);//returns b= 25
}
No comments:
Post a Comment