C# is an object oriented language developed by Microsoft for developing software that runs in a managed environment. This means, a C# application developed on Xamarin Studio can target iOS, tvOS, watchOS, macOS or Android. The notion of a managed environment is that .NET programs can be built, deployed and run on a wide variety of target platforms. (In an upcoming article, the difference between managed versus unmanaged code will be explained as will the .NET runtime and its role in the .NET environment.)
What makes C# unique, and attractive for new programmers, is that it’s simple, and powerful. Syntactically, it is as clean (if not cleaner) as Java, it is as simple as Visual Basic, and as feature rich as C++. A good way to describe it is as C++ without C++ verbosity.
Core Features of C#:
The following list of features are found in all versions of the C# programming language:
- Ability to define classes, interfaces, structures, enumerations, and delegates.
- Support for all three object oriented features: Encapsulation, Inheritance and Polymorphism.
- Type safety. Objects and arrays are initialized by zero automatically. Arrays are checked for out of bound errors.
- No need for pointers!
- Operator overloading for custom types.
- Automatic memory management through garbage collection. No need for the delete keyword of C++.
Version 2.0 (Sep. 2005)
- Static classes
- Partial classes
- Anonymous types
- Nullable types
- Delegate interface
Version 3.0 (Aug. 2007)
- Implicit types
- Object and collection initializers
- Auto-implemented properties
- Extension methods
- Query and lambda expressions
- Expression trees
- Partial methods
Version 4.0 (Apr. 2010)
- Dynamic binding
- Named and optional arguments
- Generic covariance and contravariance
- Embedded interop types
Version 5.0 (Jun. 2013)
- Async methods
- Caller info attributes
Version 6.0 (Jul. 2015)
- Roslyn (compiler-as-a-service)
- Exception filters
- Await in catch/finally block
- Auto property initializer
- String interpolation
- Nameof operator
- Dictionary initializer
- Pattern matching
- Record types
- Local functions
- Async streams
Version 8.0 (Apr. 2020)
- Readonly members – explicitly states that a member of struct doesn’t modify state.
- Default interface methods – ability to add methods to an interface in later versions.
- Using declaration – a keyword that tells the compiler that the variable being declared should be disposed at the end of the enclosing scope.
- Static local functions – so that a local function doesn’t access any variables in the enclosing scope.
- Disposable ref structs – a struct declared with the ref modifier may not implement any interfaces and so can’t implement IDisposable.
- Nullable reference types – appending the type name with a ‘?’ to indicate that a variable may be null.
- Asynchronous streams – ability to create and consume streams asynchronously.
- Asynchronous disposable – asynchronous disposable types that implement the System.IAsyncDisposable interface.
- Indices and ranges – for accessing single elements or ranges in a sequence.
Null-coalescing assignment – an operator that assigns the value of its right-hand operand to its left-hand operand only if the left-hand operand evaluates to null.
- Unmanaged constructed types – a constructed value type is unmanaged if it contains fields of unmanaged types only.
- Stackalloc in nested expressions – if the result of a stackalloc expression is of the System.Span<T> or System.ReadOnlySpan<T> type.
- Enhancement of interpolated verbatim strings – order of the $ and @ tokens in interpolated verbatim strings does not matter.
What Is The Future of C#?
The future of the C# programming language looks bright. There are many indicators suggesting this:
1. There are many C# developers worldwide:
2. According to the annual Stack Overflow surveys, C# keeps ranking in the top 10 most loved and most popular programming languages.
Frequently Asked Questions:
C# was created as part of the .NET Platform. It has been designed to grow and adjust into future technologies, and there’s no chance that C# will disappear. In fact, because Xamarin has been promoted to be a core piece of new .NET Core open-source development platform, C# is growing well beyond of Microsoft’s domains, and is used for the development of Android and iOS apps.
- Python. Python is widely accepted as the best programming language for beginner developers as it is simple and easy to use and deploy.
- R. R was developed in 1993 by Robert Gentleman and Ross Ihaka with the name “R” was taken from its developers’ names’ first letter.
- Java 8.
If you’re interested in developing Windows applications and web applications, then C# is an excellent language to learn. It is object-oriented, not as compex as C++, cross platform, backward compatible, and provides automatic garbage collection. Someone skilled in Visual Basic or Java, can pick it up quickly.
Both are great. If you are new to programming, you may find C# slower to learn and to code. C# can also do almost anything that Python is able to do, and C# is much faster at runtime partly because of the .NET runtime. Python is easy to learn (certainly easier to learn than C#) and easy to write.
Both Java and C# are object oriented, have garbage collection, and compiled. Java has a focus on WORA and cross-platform portability and it’s easier to learn. C# has been used for everything Microsoft, but is now cross-platform, and it has a slightly steeper learning curve. If you are new to coding, it’s astonishingly easy to feel overwhelmed. But either C# or Java are great starts.
2034 companies reportedly use C# in their tech stacks. Here are some of the more widely known ones:
- Delivery Hero.
- Stack Overflow.
- Durstexpress GmbH.
- Alibaba Travels.