In C#, code that uses pointers is called "unsafe code" because you don't have the safety of the system ensuring that you never modify memory that you shouldn't. In order to use pointers, you must first allow unsafe code in your project, which you do by checking the appropriate box on the Build page of the project properties. Next, you must define an unsafe block in your code. You can do that in two ways:
1. Define a block within a method in which unsafe code is allowed, e.g.
private void SomeMethod()
{
// no pointers allowed here
unsafe
{
// pointers allowed here
}
// no pointers allowed here
}
2. Define that unsafe code is allowed within the entire body of a method, e.g.
unsafe private void SomeMethod()
{
// pointers allowed here
}
If a method needs to have parameters of pointer types then you must use option 2.
For further reading on how to actually use pointers once they're allowed, this is a good place to start and you can follow the appropriate links:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.