Welcome to Coding compiler. C# programmers are becoming more popular thanks to the evolving ecosystem of the language. It writes a backend, applications, games.
We will understand what is the reason for the popularity of the language.
Meet The C#
C# has expressive syntax and is easy to learn. Everyone who worked in C, C++ or Java recognizes curly braces. Familiar with one of these languages? Then you will quickly start productive work in C#.
The syntax of the language eliminates the complexity of C++ and provides such powerful features as nullable type values, enumerations, delegates, lambda expressions, and direct memory access. C# supports generic methods and types that increase type safety and performance. Iterators allow collection creator classes to define custom iteration behaviors that are easy to use in client code. Integrated query language (LINQ) expressions make a strongly typed query a first-class language construct.
C# is an object-oriented language, which means it supports encapsulation, inheritance, and polymorphism. A class can inherit directly from one parent class, but it can implement any number of interfaces. Methods that override virtual methods in the parent class require a keyword override
to prevent accidental overriding.
In addition to all OOP goodies, the C# language facilitates the development of software components through several innovative language constructs:
- Encapsulated method signatures, called delegates, include type security alerts.
- Properties serve as accessors to the variables of the closed parts.
- Attributes provide declarative metadata about types at runtime.
- XML inline documentation comments.
- The Integrated Query Language (LINQ) provides built-in query capabilities between different data sources.
Need to interact with other Windows programs, for example, with COM objects or with the built-in Win32 DLL? Do this with C# through the Interop process. Interop allows programs written in C# to do almost everything available to programs written in C++. C# even supports pointers and the concept of “unsafe” code for cases where direct access to memory is absolutely critical.
And here .NET?
C# programs run on top of the .NET Framework, a built-in Windows component that includes a virtual runtime called the common language runtime (CLR) and a single set of class libraries. CLR is a commercial implementation of a common language infrastructure (CLI). It serves as the basis for creating executable files and development environments in which languages and libraries work together seamlessly.
C# source code is compiled into an intermediate language (IL) that complies with the CLI specification. IL code and resources such as bitmaps and lines are stored on disk as an executable file — assemblies, usually with .exe
and extensions .dll
. The assembly contains a manifest that provides information about the types, versions, culture, and security requirements of the assembly.
When the program starts, the C# assembly is loaded into the CLR, which performs certain actions based on the information in the manifest. If the security requirements satisfy the CLR, it performs a JIT compilation to convert the IL code into embedded machine instructions.
The CLR also provides other services related to automatic garbage collection, exception handling, and resource management. The code executed in the CLR is sometimes called “managed code” for comparison with “unmanaged code,” which is compiled into an embedded machine language aimed at a specific system.
Here is the relationship between compilation time and runtime of C# sources, .NET Framework class libraries, assemblies, and the CLR:
Language compatibility is a key feature of the .NET Framework. Since IL code is produced in C#, the compiler complies with the general type specification (CTS). IL code generated from C# can interact with more than twenty other CTS-compatible languages. A single assembly can contain many modules, and types can refer to each other as if they were written in the same language.
.NET Core – Cross-Platform .NET
The Core version is a modular, cross-platform open-source implementation of the general-purpose .NET standard. It contains many APIs from the .NET Framework and includes a runtime, framework, as well as tools that support various operating systems and processors. The implementation was controlled by developments from ASP.NET Core but required a more modern approach. It can be used for a variety of devices in the cloud and for embedded / IoT scenarios.
Here are the main features of .NET Core:
- Cross-platform: .NET Core provides key functionality to implement the desired features of your application, as well as the ability to reuse code regardless of your platform. It supports Windows, Linux, and macOS. You can write applications and libraries that run on all supported OS without changes.
- Open source: .NET Core is one of many projects managed by the .NET Foundation and available on GitHub. Using .NET Core as an open-source project contributes to a transparent development process and the development of an active, involved community.
- Flexible deployment: There are two main ways to deploy your application: framework dependent and standalone. In the first case, only your application and dependencies are installed. The application depends on the global version of .NET Core. In the second case, the version of .NET Core that was used to build your application is deployed with the application and its dependencies and can run in parallel with other versions.
- Modularity: .NET Core is modularized because it is released through NuGet in smaller assembly packages. Unlike one large assembly with all the built-in functionality, .NET Core is available as smaller function-oriented packages. This leads to a more flexible development model, allows you to optimize the application, including only the necessary NuGet packages.
- The advantages of a smaller application coverage area are reflected in increased security, less demanding maintenance, high performance and reduced costs on the principle of “pay only for what you use.”
Thanks to .NET Core C#, programmers can develop not only on Windows.
Xamarin: mobile development in C#
Many people think of developing for Android and iOS in the context of such embedded languages as Objective-C, Swift, Java, and Kotlin.
Xamarin allows you to develop in C# using libraries and runtime that run on iOS, Android and Windows. This compiles embedded (not interpreted) applications with sufficient performance for games.
Xamarin combines all the features of embedded platforms and adds several powerful features:
- Full binding to the basic SDK: Xamarin contains bindings to almost all the basic platform SDKs from iOS and Android. In addition, these bindings are strongly typed, which makes it easier to use and navigate, and also includes strict type checking during compilation and development.
- Interop for Objective-C, Java, C, and C++: Xamarin contains tools for directly calling the Objective-C, Java, C, and C++ libraries, which means you are free to use third-party code without reinventing the wheel. This way, you will take advantage of the existing iOS and Android libraries written in Objective-C, Java, or C / C++.
- Modern language constructs: Xamarin applications are written in C#, a modern language that contains significant improvements over Objective-C and Java. For example, features of a dynamic language, lambda, LINQ, parallel programming functions, generics and much more.
- Base Class Library (BCL): Xamarin applications use .NET BCL, a large collection of classes that has features such as XML, databases, serialization, IO, strings, and network support. Existing C# code can be compiled for future use in the application, which opens up access to thousands of libraries that can do what is not available in BCL.
- Modern IDE: Xamarin uses Visual Studio on macOS and Windows. Both versions have such modern features as code completion, project management system, template library, built-in version control.
- Mobile cross-platform support: Xamarin supports iOS, Android and Windows. Applications can have up to 90% of the total code. The library
Xamarin.Mobile
offers a unified API for accessing the resources of all platforms.
C# programmers can develop cross-platform mobile applications on Xamarin!
C# is used in machine learning
Do you already have experience in .NET and want to learn machine learning? ML.NET is an open-source cross-platform machine learning framework .
It allows you to create custom ML models in C# without leaving the .NET ecosystem. You can use all your experience and knowledge accumulated during your work with .NET to integrate machine learning into existing desktop, game, mobile or web applications, and even in IoT devices.
Here’s what you can do with ML.NET:
- Classification/categorization: Separate user feedback into positive and negative categories automatically.
- Regression / Prediction: Continuous: Predict property prices based on size and location.
- Anomaly Detection: Detect fraudulent banking.
- Recommendations: Offer products to online shoppers based on their purchase history.
Separately about the game
Unity is the most popular indie game development engine and it uses C# code. Interestingly, the engine itself is written in C++, so it frees the programmer from the need to understand the speed of execution, which is ideal for beginners.
There are other engines with C# support:
- Monogame allows you to “write a game once and play everywhere”;
- WAVE – cross-platform engine;
- Xenko is a fairly powerful cross-platform engine ;
- Duality only supports 2D ;
- Xna – the official engine from Microsoft;
- Flatredball is a 2D engine.
All of these engines allow you to write game code in C#, but Unity has definitely taken a special place in commercial development. Suffice it to recall games such as Rust and Forest – they are written in Unity, and therefore in C#.
C# programmers have great game dev opportunities!
How does all this affect the labor market?
Perhaps C# programmers did not rush to write mobile or web applications. But look what opportunities open up for those who already know C#. In addition, Microsoft plans to combine the .NET Core and the .NET Framework by 2021 with features such as the Windows Presentation Foundation (WPF).
C# programmers are no longer limited to the Windows platform. Today, they can safely try themselves as mobile, game or web developers.
The benefits for companies and startups are even more obvious: you can use one development team for all types of applications. Code support is improved, as the entire database is written in C#, including the server backend.
We should also mention machine learning – these are huge prospects for C# developers and for the language itself.
And all this you can do in Visual Studio!