C#, the Java of Microsoft
The C# language is easier to use than C++, however, it require the runtime of .NET to run programs. You can convert you C++ code with no difficulty.
C# was designed by Microsoft (tm) in 2000 for its new .NET platform as an alternative to Java, inspired (as it) by C++, by Java and various other
languages. It keeps most Java improvement, a clear object orientation.
Over time it has features that go far beyond what Java provides. It got generic programming a long time before Java. It also allows parallel programming, has a framework of event programming event (improperly called reactive).
C# may be compiled to native with the new Roslyn compiler or other tools (see links below).
On the .NET platform you can mix languages and use C# along any language, they can share the same objects. Many languages are implemented including C++, Pascal, Python, Java and even Cobol and Fortran.
From Windows to Linux
The future of the language was not clearly defined beyond the Windows plateform, until the announcement of April 2014. Previously, one could have thought that its implementation in Silverlight, once considered as the platform of the future for Web and mobile apps, will make it an essential language.
Then Microsoft moved to Metro/Modern UI, on Windows 8 using HTML 5 and JavaScript (along XAML and C#).
C# seems no longer to be viewed by Microsoft as the sole language for immersive apps on the Modern UI.
Microsoft has even created a new language, TypeScript, with classes, interfaces and modules, which is compiled into JavaScript, that reinforces the importance of the latter.
But in 2014, Microsoft announced that the new Roslyn compiler is open source like a large part of the .NET tools, and will be managed by an independent foundation. This greatly facilitates its use on all platforms.
Now it a language for desktop applications, for server-side apps, and also for mobiles, so it is universal (there is even a micro-framework for embedded systems).
Features and differences with C++ and Java
C# compiles into intermediate language, the CIL (Common Intermediate Language), which runs on a virtual machine, the CLR (Common Language Runtime). It is the implementation of the CLI, the common language infrastructure. But it may be compiled to native also like C++.
- Structs, coming from C++, are here special objects passed by value.
- A property allows to use methods as one uses variables.
- The foreach() construct allows to scan arrays.
- Delegate replaces pointers on functions used by C.
- enum, that Java lacks.
- Operators overloading exists but for the "=" one.
- It is fully object oriented, even primitive and constants are object.
- Indexers are invisible methods to access arrays with security.
- The language may access the native environment, unlike Java.
- The -> operator of C++ is replaced by a dot.
- The managed mode allows compatibility for a C++ program.
- Generic programming.
- Parallel programming.
The main difference with C++ is the use of a garbage collector to manage memory.
Compared to Java it where each class is stored in a separate file, this constraint that does not exist for C#.
Sample of C# code : Merging two strings and displaying the characters.
string s = "demo" + "trail"; foreach (char c in s) { System.Console.WriteLine(c); }
Development tools
Microsoft provides a true RAD (Rapid Application Development) for free, Visual Studio Express and they are several open source alternatives.
Visual Studio Community
A C# compiler is included.
Mono Develop
IDE for applications made in C# and other .NET languages.
BFlat
Compiler from C# to native code, for Windows, Linux, compatible with .NET 7. Make executable files.
Roslyn.
Source code of the C# compiler of Microsoft, included in Visual Studio.
NativeAOT
Runtime for applications compiled to native, on Windows, Mac and Linux.