"Lloyd Dupont" <ld@NewsAccount.galador.net> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
You should know that writting in C# is a much better, less bug prone
exception.
I haven't done real measure but I won't be surprise if the same code in
ManagedC++ is typically 50% bigger (in term of byte size of the source
code files) for writing the same set of functionalities.
That 50% time to write & 50% more opportunity for bugs!
As for pure (unmanaged) C++, some features are simply unavailable or hard
to mimic.
On the other hands in some case using ManagedC++ is a much better solution
than C# if you've got complex interop or lots of function to 'redeclare'
in C#.
Many of your observations are true for the old C++ Managed Extensions
syntax, but not fo the new C++/CLI syntax.
In some cases, C++/CLI is still more code to write, like in this one:
<code language="C#">
Sting Text {
get() { ... }
set() { ... }
}
</code
<code language="C++/CLI">
property Sting^ Text {
String^ get() { ... }
void set(String^ value) { ... }
}
</code>
but on many cases it is even less code:
<code language="C++/CLI">
property String^ Text;
</code>
will automatically allocate the backing storage and implement getters and
setters.
The biggest coding benefit comes with implicitly dereferenced access and
interop:
<code language = "C#">
class X : IDisposable {
private Object oLock = gcnew Object;
private Mutex mtx = gcnew Mutex(...);
public void Dispose() {
mtx.Dispose();
}
public void f() {
lock(oLock) {
using (FileStream fs = gcnew FileStream(".....", ....))
using (...) {
...
}
}
}
};
</code>
<code language = "C#">
class X {
Object oLock;
Mutex mtx(...);
public:
void f() {
msclr::lock(%oLock)
FileStream fs(".....", ....));
... other implicitly dereferenced things ...
...
}
};
</code>
C++/CLI has many advantages here:
1) It is not necessary to implement IDisposable yourself, the compiler does
this for you.
2) Notice that C#'s lock is a language construct while msclr:lock is a heper
class that comes with C++/CLI. It is easy to implement your own helpers and
even the standard one has a feature, that you will miss in C#:
msclr::lock(%oLock, 2000);
Acquires the lock with a 2 second timeout.
Marcus Heege