The C# Programming Language
How is it that after 18 years from its first release, C# is suddenly, strongly rising in the TIOBE index?
C# is a computer programing language first appeared on the scene 21 years ago (2000). It is a strongly typed, object-oriented, imperative, concurrent, generic, reflective, functional and procedural programming language with automatic memory management whose main purposes have been historically two, the second of which absolutely unofficial:
- provide to Microsoft internal programmers as well as Microsoft client programmers a new language, coupled with a modern execution environment (.NET), as powerful as C++ to program with, but way easier, safer and secure to use and to deploy software applications with
- create a proprietary execution environment and programming language alternative to Java starting from the good peculiarities of that technology and extending from them without the hassle of being sued by others for not complying to specifications and requirements neither born in Microsoft nor convenient for the Microsoft monopoly of those days
Created by Anders Hejlsberg, C# was very similar to Java in the beginning, but during the years and with the release of successive versions the differences between the two languages grew more and more. Today C# and it's coupled environment .NET are widely adopted technologies with a recent further boost in their popularity given by the release in 2016 of .NET Core which is the first Microsoft fully supported version of the software framework which is free, open-source (MIT and Apache 2 licenses) and available for Windows, Mac OS X and Linux, although it still does not offer all the functionalities of the Windows only version (.NET Framework).
First glance at the code
Example: The classic "Hello world" program written in C#:
Main features of C#
C# has a type system that is checked at compile time and is more type safe than C++. For example, implicit conversions by default are only allowed when considered safe, such as widening of integers. However C# supports strongly typed implicit variable declarations with the keyword var, and implicitly typed arrays with the keyword new followed by a collection initializer.
C# has a unified type system called Common Type System (CTS) which means that all types, including those such as integers, are subclasses of the System.Object class. As such there is no concept of primitive data type in C#, the closest concept to it is what Microsoft call in the documentation "simple types", which belongs to the family of the Value types, in fact CTS separates data types into two main categories: Reference types and Value types. Anyway, since version the C# specification (version 4) defines keyword aliases for some types.
C# is object-oriented, but multiple inheritance is not allowed. A class can inherit characteristics and features only from a single class, but can implement more than one interface. Also classes cannot inherit from simple types as listed in the table above. In fact even if in C# every type is an Object those types are 'sealed' and cannot be derived.
Memory management in C# is automatic. A garbage collector at run-time provides to free the memory resources allocated for the object instances that become not reachable any more by any part of the running application.
C# has complete support and offers libraries and language costructs to allow the concurrent execution of multiple threads within the same process.
C#, as a language of the .NET Framework family has access to the common language runtime and the .NET Framework classes and services that enable developers to write secure code and enable system administrators to customize the permissions granted to code so that it can access protected resources. The runtime also provides facilities to use cryptography and role-based security.
C# execution performance are those of the .NET Framework whose performance are substantially similar to those of modern Java.
C# applications need a .NET platform to run. Confusion often rises when trying to understand on which platform a .NET application can run. The problem is that while most of the .NET technologies and languages have been standardized and often open sourced by Microsoft, allowing even third parties to provide their own implementations of the same, some libraries, and usually exactly those that are more often used by Windows developers, are neither free and open source nor available on non Windows platforms.
Notable softwares/platforms/products written in C#
- Stack Overflow has been developed in C#
- Unity, one of the most adopted game engine of the world, offer the ability to script games in C#
- Most C# and .NET developments are not from startups or open sorce projects. Wider adoption of the platform is seen in the enterprise sector for companies like banks, healtacere providers, insurance issuers and so on
Best books for learning C#
|C#: A Beginner's Guide (Beginners Guides)|
Designed for Easy LearningC#: A Beginner's Guide offers a step-by-step approach to learning object-oriented programming with C# and the .NET Framework while preparing you for data driven-development. More than 150 easy-to-follow examples are... (continue on Amazon)
For experienced programmers
|Effective C# (Covers C# 6.0), (includes Content Update Program): 50 Specific Ways to Improve Your C# (3rd Edition) (Effective Software Development Series)|
50 ways to harness the full power of C# 6.0Wagner’s clear, practical explanations, expert tips, and realistic code examples have made Effective C# indispensable to hundreds of thousands of developers. Drawing on his unsurpassed C# experience, he addresses everything from... (continue on Amazon)