Archived

This topic is now archived and is closed to further replies.

DuckMaestro

C# worth it?

Recommended Posts

DuckMaestro    122
I''m experienced in java 1.1, 1.2 and c/c++, win32api. I''m wondering if C# is going to save me coding-time but without taking away much coding-power. I like to be able to access memory directly sometimes (files loaded into memory) and do pointer math... i remember in java that you can''t exactly do things that way..... what about C#? are there pointers/can u do pointer math? or i guess another question would be, if you''ve switched to C# from C, what common coding practices were not longer doable and what did u have to do to get around it. thanks - Duck

Share this post


Link to post
Share on other sites
Zipster    2365
You can do pointer stuff in C#, however you have to explicitly declare the sections of code in which you''ll be doing "unsafe" operations (that''s literally what it''s known as) so the compiler knows.

I was an experienced C++ programmer, and while I didn''t necessarily switch to C# I wanted to give .NET and the managed language(s) a try. I found C# very addicting The fact that I didn''t have to worry about all tedious memory management anymore alone was worth it, plus all the cool language features (delegates, events, properties, etc.) make it a pleasure to work with. Don''t get me wrong, I now like both C++ and C#, but I''m starting to like Windows Forms for Windows applications! You can use C++ with Windows Forms, but you have to use managed extensions. Just some extra keywords to remember, but I''d say .NET integrates better with C#.

Share this post


Link to post
Share on other sites
Zipster    2365
I haven't mixed C# with managed C++ yet, but that would work seamlessly due to the fact that they both would compile to assemblies, which can be referenced in other projects.

As for interop (using regular C/C++ from a managed environment), I've done that too. You can import C/C++ functions from a native module, and call the functions within an unsafe context. The only hard part is figuring out which managed types correspond to which unmanaged types, but there are several MSDN references which tell you what combinations work best, as well as the Marshal class, which you can tinker with if you want to perform custom marshaling. Some are obviously, like the managed Int32 type for passing pointers. But some aren't so obvious, like using StringBuilder for mutable character buffers (ex. if you want to use GetWindowText).

But I should mention it now, that using unsafe when you don't have to has some negative security impacts on you assembly. From the view-point of .NET security, an unverifiably type-safe assembly is the least trusted type of assembly.

[edited by - Zipster on May 26, 2004 7:39:32 PM]

Share this post


Link to post
Share on other sites