Avinash K R
Avinash K R

Reputation: 1

c++ to c# Conversion Queries

I am Re-Writing an C++ assembly into a c# assembly. I am facing an issue while handling pointers that refers to a particular memory address. Ex : int a=0; int *b=&a;

I have done some research and found that we can make the method as unsafe and use pointers. apart from making the method as unsafe, is there any other way we can handle this in c# that is logically correct according to C++.

Also please let me know if there is any C+++ assemblies i need to keep in mind that might cause trouble while converting to c#.

Upvotes: 0

Views: 50

Answers (1)

Jeffrey
Jeffrey

Reputation: 11430

For your specific snippet, you can use the ref keyword:

int a = 0;
ref int b = ref a;

That should behave just like C++. No need for unsafe code.

Upvotes: 1

Related Questions