
C# produces better IL than C++
Egbert,
Quote:
> Got one clue already to use the S prefix for strings
> C++
> saMails->set_Item(0, S"Hello World");
> IL:
> IL_000c: ldstr "Hello World"
> IL_0011: callvirt instance void
> [mscorlib]System.Collections.IList::set_Item(int32,
> object)
> STILL why does C# use this:
> IL_000a: ldstr "Hello WOrld"
> IL_000f: stelem.ref
> while C++ uses this
> IL_0011: callvirt instance void
> [mscorlib]System.Collections.IList::set_Item(int32,
> object)
Because that's what you're telling it to do. You are using the Item property
of the Array class directly, which is inherited from IList; hence the call
to IList::set_Item. If you were using array syntax, it would do the same as
C#:
String * saMails[] = new String*[1];
saMails[0] = S"hello world";
IL_0003: newarr [mscorlib]System.String
IL_0008: stloc.0
IL_0009: ldloc.0
IL_000a: ldc.i4.0
IL_000b: ldstr "hello world"
IL_0010: stelem.ref
--
Tomas Restrepo