C# is a programming language whose core syntax looks very similar to the syntax of Java. However, calling C# a Java clone is inaccurate. In reality, both C# and Java are members of the C family of programming languages (e.g., C, Objective C, C++) and, therefore, share a similar syntax.
The truth of the matter is that many of C#’s syntactic constructs are modeled after various aspects of Visual Basic (VB) and C++. For example, like VB, C# supports the notion of class properties (as opposed to traditional getter and setter methods) and optional parameters. Like C++, C# allows you to overload operators, as well as create structures, enumerations, and callback functions (via delegates).
Moreover, as you work through this text, you will quickly see that C# supports a number of features traditionally found in various functional languages (e.g., LISP or Haskell) such as lambda expressions and anonymous types.
Furthermore, with the advent of Language Integrated Query (LINQ), C# supports a number of constructs that make it quite unique in the programming landscape. Nevertheless, the bulk of C# is indeed influenced by C-based languages.
Because C# is a hybrid of numerous languages, the result is a product that is as syntactically clean (if not cleaner) as Java, is about as simple as VB, and provides just about as much power and flexibility as C++. Here is a partial list of
core C# features that are found in all versions of the language:
1-No pointers required! C# programs typically have no need
for direct pointer manipulation (although you are free to drop
down to that level if absolutely necessary.
2-Automatic memory management through garbage collection. Given this, C# does not support a delete keyword.
3-Formal syntactic constructs for classes, interfaces,structures,enumerations, and delegates.
4-The C++-like ability to overload operators for a custom type, without the complexity (e.g., making sure to “return *this to allow chaining” is not your problem).
5-Support for attribute-based programming. This brand of
development allows you to annotate types and their members to further qualify their behavior. For example, if you mark a method with the [Obsolete] attribute, programmers will see your custom warning message print out if they attempt to make use of the decorated member.
With the release of .NET 2.0 (circa 2005), the C# programming language was updated to support numerous new bells and whistles, most notability the
following:
1-The ability to build generic types and generic members.
Using generics, you are able to build efficient and type-safe
code that defines numerous placeholders specified at the
time you interact with the generic item.
2-Support for anonymous methods, which allow you to supply an inline function anywhere a delegate type is required.
3-The ability to define a single type across multiple code files
(or if necessary, as an in-memory representation) using the
partial keyword.
.NET 3.5 (released circa 2008) added even more functionality to the C# programming language, including the following features:
1-Support for anonymous types that allow you to model the
structure of a type (rather than its behavior) on the fly in
code.
2-The ability to extend the functionality of an existing type
(without subclassing) using extension methods.
3-Inclusion of a lambda operator (=>), which even further
simplifies working with .NET delegate types.
4-A new object initialization syntax, which allows you to set
property values at the time of object creation.
.NET 4.0 (released in 2010) updated C# yet again with a handful of features:
1-Support for optional method parameters, as well as named
method arguments.
2-Working with generic types is much more intuitive, given that
you can easily map generic data to and from general
System.Object collections via covariance and
contravariance.
With the release of .NET 4.5, C# received a pair of new keywords (async and await), which greatly simplify multithreaded and asynchronous programming. If you have worked with previous versions of C#, you might recall
that calling methods via secondary threads required a fair amount of cryptic code and the use of various .NET namespaces. Given that C# now supports language keywords that handle this complexity for you, the process of calling methods asynchronously is almost as easy as calling a method in a synchronous manner.
This brings us to the current version of C# and .NET 4.6, which introduces a number of minor features that help streamline your codebase. You will see a number of details as you go through this text; however, here is a quick rundown of some of the new features found in C#:
1-Inline initialization for automatic properties as well as
support for read-only automatic properties
2-Single-line method implementations using the C# lambda
operator
3-Support of “static imports” to provide direct access to static
members within a namespace
4-A null conditional operator, which helps check for null
parameters in a method implementation
5-A new string formatting syntax termed string interpolation
6-The ability to filter exceptions using the new when keyword