I’ve been programming professionally for 10 years or so, most of that in C, with a fair amount of C++ more recently, but, up until my present job, I’ve worked entirely on video game consoles. Now I’m working on Windows, and I’d like to write a simple little tool with some buttons and pulldown menus and so forth. Various smart people say that things like that are VERY easy to do in C#. However, (a) I don’t know a thing about C#, and (b) this tool would need to use our pre-existing networking and utility code, which is in C.
So:
(1) How easy is it to learn C#, coming from a C/C++ background?
(2) How easy is it to write a tool where the interface is in C# but it calls some number of C functions, or perhaps vice versa?
Thanks
C# is easy for someone who already knows a C-like language. The syntax is similar, the object model is basically C++ with managed memory, and it has all Microsoft’s various Visual tools behind it, so yay. It has more syntax than C, but less than C++. It is allegedly easy to call into C; one of MS’s stated design goals for C# was to make writing native code easy on Windows (to differentiate it from Java and its miserable JNI, I presume). They have about a million tutorials on it on MSDN, anyway.
Can’t speak for #2 at all, but #1 - I agree. My background was C/C++ and I had no trouble picking up C# in a five-day training course. Syntax was easy. Development environment and the structure may take a little getting used to - Visual Basic experience would help a bit with that aspect.
I just went from a C/C++ background to C#, and I love it. The hardest part is learning all the stuff that C# already does that you had to do “by hand” with C/C++. There’s just assloads of functions built-in to the language, like XML and http functions.
Right now I’m working on a project whereby I need to make a .NET “wrapper” around functions in a device API that was written for C. Got it working today mostly, it wasn’t difficult. Basically, I made a managed C++ dll project in Visual Studio that contained an unmanaged class to call the C API functions, and I made a managed Class that created an instance of the unmanaged class, and called the functions of that unmanaged class. Then my C# project referenced the dll, instantiated the managed class and called its methods (which in turn called the unmanaged methods of the unmanaged class).
I think that sounds a lot more complicated than it actually is. Plus, there very well might be simpler and more direct ways of doing it; I’m pretty new to C#/.NET and would not be surprised one bit if I missed an easier solution.
Also remember that if you’re using Visual Studio 2005, C++.NET is also an option (and a pretty good one). It gets all of the whiz-bang Rapid GUI and automation stuff in a language that’s only slightly different from what you’re used to (the .NET objects are garbage-collected, so many C++ construction/destruction metaphors don’t work with them), plus calls into C/C++ are basically free. It really is the best of both worlds if you’re already comfortable in C++.
The 2003 version of C++ is much less functional, and there are big changes between the two.
C# is much closer to Java than C++, but wouldn’t be hard to learn. VB.NET is also pretty close to Java, and more fun to learn. You can mock the: “Overridable MustOverride Private Sub Foobar(ByValue variablename as VariableType)…End Sub” over-the-top verbose syntax while still understanding all of the concepts. Plus VB has better (ok, “more”) Intellisense-style stuff in it: you can almost program-by-pulldown, and it will highlight syntax errors BEFORE you compile, which C# is weaker at.
I’ll echo the others - it’s very easy to program in C# if you know C/C++. The UI side is easier if you’re familiar with VB as well, but not too hard to get if you’re not.
[QUOTE=Taran]
The syntax is similar, the object model is basically C++ with managed memory
[/quote]
Well, it’s really closer to Java. For example, in C# all class instances are allocated on the heap. There’s no stack-based allocation with automatic construction and destruction (thus no RAII pattern). There’s no multiple inheritance, only interfaces. Also, IIRC, class identity never changes during construction, whereas in C++ an object “grows” through every one of its base classes as the constructors are called, which makes a difference if any of the base constructors call virtual methods.
[QUOTE=Mr2001]
Well, it’s really closer to Java. For example, in C# all class instances are allocated on the heap. There’s no stack-based allocation with automatic construction and destruction (thus no RAII pattern). There’s no multiple inheritance, only interfaces.
[/quote]
Heh, good point. “With managed memory” covers an astonishing variety of stuff. No copy constructors, no real destructors (finalizers don’t count), and of course no MI.
:eek: I never knew it did that. How appalling. Thanks.