MC++ wrapping mytesries
-
Take a look at this MC++ class :-
public \_\_gc class Class2 { public: int Abc() { int y=8; return y; } };
Now here is some C# code that instantiates this class :-
Class2 c1 = new Class2(); int y=c1.Abc();
This is confusing to me. Abc() returns an
int
and not anInt32
. It returns a C++int
. Now we know that the C#int
actually maps to a .NETInt32
. What puzzles me is how the C++int
auto-converts into a C#int
which auto-boxes to aInt32
!
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
-
Take a look at this MC++ class :-
public \_\_gc class Class2 { public: int Abc() { int y=8; return y; } };
Now here is some C# code that instantiates this class :-
Class2 c1 = new Class2(); int y=c1.Abc();
This is confusing to me. Abc() returns an
int
and not anInt32
. It returns a C++int
. Now we know that the C#int
actually maps to a .NETInt32
. What puzzles me is how the C++int
auto-converts into a C#int
which auto-boxes to aInt32
!
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
There is no mystery C++ .NET C# int -> System.Int32 -> int System::String->System::String->string So C++ compiler actually emits metadata as System.Int32. C# compiler reads System.Int32 and maps it to int.
-
There is no mystery C++ .NET C# int -> System.Int32 -> int System::String->System::String->string So C++ compiler actually emits metadata as System.Int32. C# compiler reads System.Int32 and maps it to int.
Rama Krishna wrote: So C++ compiler actually emits metadata as System.Int32. C# compiler reads System.Int32 and maps it to int. Thanks Rama!!! Nish
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
-
Take a look at this MC++ class :-
public \_\_gc class Class2 { public: int Abc() { int y=8; return y; } };
Now here is some C# code that instantiates this class :-
Class2 c1 = new Class2(); int y=c1.Abc();
This is confusing to me. Abc() returns an
int
and not anInt32
. It returns a C++int
. Now we know that the C#int
actually maps to a .NETInt32
. What puzzles me is how the C++int
auto-converts into a C#int
which auto-boxes to aInt32
!
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
int doesn't exist in .NET , the closest is "native int" used with p/invoke and com interop scenarios ... The System.Int32 is the real datatype , int is simply a "alias". For real interop with different languages used with the same project we should use the real ones, not the fakes , it's helps a lot :-) I'm be reading about IL code generation and CLR internals , and in fact .NET is a fascinating beast :omg: Microsoft have done a great work :-D Cheers, Joao Vaz A person who is nice to you, but rude to the waiter, is not a nice person - Natalie Portman (Padme/Amidala of Star Wars)