"Zytan" <zy**********@yahoo.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
It seems I cannot return a reference to a value type as the return
value of a method. I will have to use an out parameter instead. Is
there another way to do it?
Zytan
Not from C#, two languages I know off, ILAsm and C++/CLI, allows you to return a reference
to a value type, as long as it's not in a stack location.
Here's a sample using ILAsm as a producer and CPP as consumer, other managed languages
cannot party.
// ILAsm file: refret.il
..assembly extern mscorlib {}
..assembly refret {}
..class public Test extends [mscorlib]System.Object {
.field static int32 s_x
.method public static int32& f() {
ldsflda int32 Test::s_x
ret
}
}
Save as refret.il , and
compile with: ilasm /out:refret.dll /dll refret.il
//C++/CLI consumer
#using "refret.dll"
int main()
{
// call a method that returns a ref to an int.
int% ret = Test::Foo();
...
}
save as : userefret.cpp
and compile with
cl /clr:safe userefret.cpp
Willy.