Back to: C#.NET Tutorials For Beginners and Professionals
Introduction to C# Programming Language
In this article, I am going to give a brief introduction to C# Programming Language. Please read our previous article where we discussed .NET Framework Architecture and Components in detail. At the end of this article, you will understand mostly What is C#, Features of C#. What are the different types of applications developed using C#, C# version history, and what C# can do for us?
Why did C#.NET come to the market?
C#.NET Programming Language is mainly designed to overcome the disadvantages of C and C++ and to develop internet applications (web applications) by achieving platform independence.
Why C# is so much popular nowadays?
C#.NET is so much popular nowadays because of the following reasons.
C# is Simple and Familiar:
C# is simple because C# simplifies the programmer’s job by avoiding certain features of C and C++. C# avoids explicit memory management. Memory management in C# is automatic. It is done by CLR. So, there is no chance of memory leakage. There is a pointer concept in C# but it is restricted. C# is very familiar to programmers because it is modeled on the C and C++ languages. C# uses many features of C and C++; therefore, C# codes look like C and C++ codes. We can say C# is the simplified version of C and C++.
C# is Portable:
Portability allows the programmer to write the same code for different machines (operating systems). C# provides portability in two ways
- Source Code Portability
- IL Code Portability (DLL and EXE)
In C#, we can write the source code in Multiple OS and get the output. Even though we can IL Code Portability is also available. So, once you have the DLL and EXE, then you can use those DLLs and EXEs on different OS and you can get the output as expected. Whereas in the case of C and C++ there is only source code portability.
C# is Architecturally Neutral:
The behavior of C# programs doesn’t change when we move from one system to another which means it will provide the same output in every machine because in C# memory layout decisions are not made at compile time, it is made at run time by CLR. It is because of CTS (Common Type System) and in our coming session we will discuss it in detail. But in the case of C and C++ programs, the behavior changes when we move the program from one system to another and the reason for this is the size of data types varies from OS to OS.
C# is Secured:
C# is secured because the C# programs are executed in a secured environment called CLR. CLR will provide security to the C# programs.
C# is Robust:
Robust means Strong. C# is a strong type-checking language having strict type-checking during both compilation time and execution time which allows us to develop error-free applications and programs.
C# is Distributed:
Using C# Programming Language, we can develop distributed applications whose resources are shared by more than one client. An application or program whose resources are shared by more than one client is called a distributed application. As C# is used for developing such applications for example WCF Applications, Restful Services, etc. So, C# is a distributed programming language.
C# is Multithreaded:
A process is divided into several small parts known as threads or lightweight processes. Sending multiple threads to the processor for processing is known as multithreading. Multi-threading means handling multiple tasks simultaneously. For example, we can listen to music while scrolling a page and at the same time we can download an application from the internet on a computer.
If multiple threads are used to execute your application code, then it is called Multithreading. Multithreading is a mechanism to implement Concurrent Programming where multiple threads execute the code simultaneously. And using C# Programming language we can develop multithread applications. So, C# supports multithreaded programming.
C# is Dynamic:
C# 4.0 introduced a new type called dynamic that avoids compile-time type checking. A dynamic type escapes type checking at compile-time; instead, it resolves the type at run time. So, if you don’t know the type of data that you want to store, then you can use dynamic as the data type, and at runtime based on value or data, the type will automatically resolve. So, C# is dynamic.
C# is Compiled and Interpreted:
We know a programming language is either compiled or interpreted. But C# combines both approaches. That’s why C# is called a two-stage system.
First C# compiler CSC translates source code into an intermediate language code known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language) code. But these MSIL or CIL or IL codes are not machine instructions. So, in the second stage, these MSIL or CIL, or IL codes are interpreted by the C# interpreter (One Component of CLR called JIT- Just in Time Compiler). As a result, machine instructions will be generated which are directly executed by the machine. Hence, we are saying C# is both interpreted and compiled language.
C# is Object-Oriented:
Except for the primitive data types, all elements in C# are objects. Object-oriented is not a programming language, it is a programming technique or concept, or principle which defines a set of rules and regulations for organizing the data and instructions. The concepts provided by oops are as follows
- Encapsulation
- Abstraction
- Polymorphism
- Inheritance
The Programming Language which supports these four features is known as an Object-Oriented Programming Language. And C# Programming Language supports these four features, so C# is Object-Oriented.
C# is Platform Independent:
Many Programming Languages are compatible with only one platform. Now, with the introduction of .NET Core or .NET, C# was specifically designed to be platform-independent. C# applications with .NET Core or .NET can be run on Windows, Linux, and Mac operating systems. So, we can say C# is Platform Independent with .NET Core or .NET.
Automatic Memory Management:
The .NET Framework automatically manages memory allocation and de-allocation for objects. When a dot net application runs, lots of objects are created. At a given point in time, it is possible that some of those objects are not used by the application. Garbage Collector in .NET Framework is nothing but a Small Routine or you can say it is a Background Process that runs periodically and try to identify what objects are not being used currently by the application and de-allocates the memory of those objects. So, as a developer, we need not worry about how memory allocation and deallocation are done in .NET Applications.
Exception Handling:
C# Provides Strong Exception Handling Features which can be used to stop the Abnormal Termination of the program and you can also provide user-understandable messages when an exception is raised.
C# Definition based on the above features:
C# is just a Simple, Secure, Robust, Portable, Platform-Independent, Architectural Neutral, Multithreaded, Automatic Memory Management, Object-Oriented Programming Language with a strong type Exception Handling mechanism for developing different kinds of applications such as Web, Windows Form, Console, Web Services, Mobile Apps, etc. which can be run on different Operating Systems such as Windows, Linus, and Mac.
Features of C#
Although C# constructs closely follow traditional high-level languages, C and C++ and being an object-oriented programming languages. It has a strong resemblance with Java, it has numerous strong programming features that make it endearing to a number of programmers worldwide. Following is the list of a few important features of C# −
- Simple: C# is a simple language in the sense that it provides a structured approach (to break the problem into parts), a rich set of library functions, data types, etc.
- Modern Programming Language: C# programming is based upon the current trend and it is very powerful and simple for building scalable, interoperable, and robust applications.
- Object-Oriented: C# is an object-oriented programming language. OOPs makes development and maintenance easier whereas in Procedure-oriented programming language it is not easy to manage if code grows as the project size grows.
- Type-Safe: C# type safe code can only access the memory location that it has permission to execute. Therefore, it improves the security of the program.
- Interoperability: The interoperability process enables the C# programs to do almost anything that a native C++ application can do.
- Scalable and Updateable: C# is an automatic scalable and updateable programming language. For updating our application, we delete the old files and update them with new ones.
- Component Oriented: C# is a component-oriented programming language. It is the predominant software development methodology used to develop more robust and highly scalable applications.
- Structured Programming Language: C# is a structured programming language in the sense that we can break the program into parts using functions. So, it is easy to understand and modify.
- Rich Library: C# provides a lot of inbuilt functions that make development fast.
- Fast Speed: The compilation and execution time of the C# language is fast.
Types of Applications Developed using C#:
With the help of the C# programming language, we can develop different types of secured and robust applications:
- Window applications
- Web applications
- Distributed applications
- Web service applications
- Database applications
- Mobile Applications, etc
C# History
The history of the C# Programming Language is interesting to know. C# is pronounced as “C-Sharp”. It is an object-oriented programming language provided by Microsoft that runs on the .NET Framework, NET Core, or .NET. Anders Hejlsberg is known as the Founder of C# Programming Language.
C# is pronounced as “C-Sharp”. It is one of the Object-Oriented Programming Languages provided by Microsoft that runs on the .NET Framework, .NET Core, or .NET. C# is a modern, general-purpose, object-oriented programming language developed by Microsoft and approved by European Computer Manufacturers Association (ECMA) and International Standards Organization (ISO).
It is based on C++ and Java, but it has many additional extensions and features that are used to develop different types of Applications such as Windows, Web, Restful services, etc. C# was first released in the year 2002. It was introduced with .NET Framework 1.0 and the current version of C# is 10.0. Let us see the important features introduced in each version of C# as follows.
C# Version History
C# was first introduced with .NET Framework 1.0 in the year 2002 and evolved much since then. The following table lists important features introduced in each version of C#:
C# 1.0:
.NET Framework: .NET Framework 1.0/1.1
Visual Studio: Visual Studio .NET 2002
Important Features:
- Basic features
C# 2.0
.NET Framework: NET Framework 2.0
Visual Studio: Visual Studio 2005
Important Features:
- Generics
- Partial types
- Anonymous methods
- Iterators
- Nullable types
- Private setters (properties)
- Method group conversions (delegates)
- Covariance and Contra-variance
- Static classes
C# 3.0
.NET Framework: .NET Framework 3.0\3.5
Visual Studio: Visual Studio 2008
Important Features:
- Implicitly typed local variables
- Object and collection initializers
- Auto-Implemented properties
- Anonymous types
- Extension methods
- Query expressions
- Lambda expressions
- Expression trees
- Partial Methods
C# 4.0
.NET Framework: .NET Framework 4.0
Visual Studio: Visual Studio 2010
Important Features:
- Dynamic binding (late binding)
- Named and optional arguments
- Generic co- and contravariance
- Embedded interop types
C# 5.0
.NET Framework: .NET Framework 4.5
Visual Studio: Visual Studio 2012/2013
Important Features:
- Async features
- Caller information
C# 6.0
.NET Framework: .NET Framework 4.6
Visual Studio: Visual Studio 2013/2015
Important Features:
- Expression Bodied Methods
- Auto-property initializer
- nameof Expression
- Primary constructor
- Await in the catch block
- Exception Filter
- String Interpolation
C# 7.0
.NET Framework: .NET Core 2.0
Visual Studio: Visual Studio 2017
Important Features:
- Out Variables in C#
- Pattern Matching in C#
- Digit Separators in C#
- Tuples in C#
- Splitting Tuples in C#
- Local Functions in C#
- Ref Returns and Ref Locals in C#
- Generalized Async Return Types in C#
- Expression Bodied Members in C#
- Thrown Expression in C#
- Async Main in C#
C# 8.0
.NET Framework: .NET Core 3.0
Visual Studio: Visual Studio 2019
Important Features:
- Default interface methods
- Nullable reference types
- Pattern matching enhancements
- Asynchronous streams / Asynchronous disposable
- Using declarations
- Enhancement of interpolated verbatim strings
- Null-coalescing assignment
- Static local functions
- Indices and ranges
- Unmanaged constructed types
- Readonly-Member
- Stackalloc in nested expressions
- Disposable ref structs
C# 9.0
.NET Framework: .NET 5.0
Visual Studio: Visual Studio 2019
Important Features:
- Top-level statements
- Record types
- Init-only setters
- Enhancements to pattern matching
- Natural-sized integers
- Function pointers
- Target type new
- Target type conditional
- Static anonymous methods
- Covariant return types
- Lambda discard parameters
- Attributes on local functions
C# 10.0
.NET Framework: .NET 6.0
Visual Studio: Visual Studio 2022
Important Features:
- Record structs
- Improvements in structure types
- Interpolated string handlers
- global using directives
- File-scoped namespace declaration
- Extended property patterns
- Improvements in lambda expressions
- Allow const interpolated strings
- Record types can seal ToString()
- Improved definite assignment
- Allow both assignment and declaration in the same deconstruction
- Allow AsyncMethodBuilder attribute on methods
- CallerArgumentExpression attribute
- Enhanced #line pragma
What can C# do for us?
Well, the answer is, a lot. I would say, nearly anything. C# can be used to write Windows clients Applications, Web applications, Mobile Apps, Enterprise Software, Backend, and Service-Oriented Applications. The following image demonstrates the C# world and applications ecosystem. The following image demonstrates the C# world and applications ecosystem.
As you can see from the above image, the C# language can be used to build any and all kinds of applications. Not only Windows or Web applications but C# can be used to build mobile, Windows Store, and Enterprise applications. C# can also be used within the SQL Server database to build reports, jobs, and modules to do the backend work. Here is a list of types of applications C# can develop.
- Cloud-native apps and services
- Windows client applications
- Windows libraries and components
- Windows services
- Web applications
- Web services and Web API
- Native iOS and Android mobile apps
- Backend services
- Azure cloud applications and services
- Backend database using ML/Data tools
- Interoperability software such as Office, SharePoint, SQL Server, and so on.
- Artificial Intelligence and Machine learning
- Blockchains and distributed ledger technology including cryptocurrency
- Internet of Things (IoT) devices
- Gaming consoles and gaming systems
- Video games