Features of C# - C# Academy: Learn the Basics of C# (2014)

C# Academy: Learn the Basics of C# (2014)

Chapter 2. Features of C#

Even though they’re part of the same family, C# is set apart from C, C++, and Java because of the following:

Typing

When it comes to typing, var, short for variable, should be used as an implicit declaration of the said variable. The keyword new should then be used for new arrays as sign of collection initializer. This makes it more type-safe than C++.

Bool, a strict Boolean Data Type is also used so that statements could take conditions. If and while are also used if the true operator is being implemented.

C# doesn’t use the“true or false integer”approach so that exact bool data could be used. This could then prevent certain programming mistakes, such as if (a = b) from being made.

The completion of integers is enforced at the beginning of programming, or during runtime, and there could be no implicit reactions between integers and Booleans, and any conversions should be specifically marked as implicit or explicit and should make use of copy operators and constructors.

There is also explicit support for contravariance and covariance, together with scope and enumeration, without the usage of global functions and variables. It also cannot shadow any kind of blocks.

Portability

C# almost directly reflects the Common Language Infrastaracture (CLI) with intrinsic types that are implemented in CLI values. It also means that common runtimes should not be targeted, and that the Common Intermediate Language (CIL) should be generated to get the right machine codes.

Methods and Functions

Again, virtual should be used in C#. This way, methods could easily be ridden by subclasses and extension methods could be used so that programmers could use static methods for both the object and its derivatives.

Blinding runtime method could be done with the help of the dynamic derivative. The keyword delegate should then be used for strong-type function pointers, just like the pseudo C++ signal and other publish-subscribe events.

Synchronizedmethod calls could also be used—like how it’s done in Java. This could happen with the attribute [MethodImpl (MethodImplOptions.Synchronized)]. The word lock could be used as a symbol of mutually exclusive locks.

Meta Programming

GCC Functionality could be copied based on platform and other preferences.

Memory Access

When it comes to Memory Access, the word unsafecould be used for blocks that determine memory address pointers. These could then help you find well-defined null values or live objects, but you won’t be able to obtain references to dead objects or random blocks of memory because more often than not, it’s quite impossible to get dead object references.

Take note that you couldn’t free managed memory explicitly because garbage cannot be collected.

Common Type System

A unified type system is used in C#. It implies all subclasses of system.object that could inherit the ToString () method.

This also works two ways: First, there’s the Reference Type. This gives the notion of identity that’s known as referential, even there’s similar data in the two of them. Comparisons such as default equality and inequality reflect this type. For this, you could use System.Stringso you’d be able to copy instances that already exist. IComparable or IClonable could also be used.

Meanwhile, there are Value Types—which stand on their own and cannot be dependent on each other. These could be primitive types, such as 32 bit integers (int) and floating point numbers (float). You could use struct (for defined structures) and char (for bitcode units). System.DataTimecould also be used. For general purposes, though, you could use System.ValueType.

Namespace

When it comes to namespace, there should either be C++ or Java namespace. You could work the way you would with a package.

Polymorphism

Multiple Inheritance is not supported in C#. However, classes are allowed to provide any number of interferences, mostly as architectural requirement of the program.

Each method could then be implemented through invocation. Operator Overloading should also be supported.

Functional Programming

C# gives limited support for first class functions—and they are all based on syntax.

Boxing and Unboxing

Boxing means that you have to convert value-type objects that could help implicit changes in C#.

As for unboxing, this means you’re letting reference values be converted into value types so that you could make use of type cast explicits that could be unboxed to nullified Ts.

Exceptions

There are no check exceptions present in C#, all thanks to versionality and scalability.