Introduction to C# Programming Language
Posted by Superadmin on November 15 2023 04:54:10

Introduction to C# Programming Language

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

  1. Source Code Portability
  2. 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

  1. Encapsulation
  2. Abstraction
  3. Polymorphism
  4. 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# −

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Interoperability: The interoperability process enables the C# programs to do almost anything that a native C++ application can do.
  6. 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.
  7. 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.
  8. 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.
  9. Rich Library: C# provides a lot of inbuilt functions that make development fast.
  10. 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:

  1. Window applications
  2. Web applications
  3. Distributed applications
  4. Web service applications
  5. Database applications
  6. 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.

Introduction to 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:

  1. Basic features
C# 2.0

.NET Framework: NET Framework 2.0

Visual Studio: Visual Studio 2005

Important Features:

  1. Generics
  2. Partial types
  3. Anonymous methods
  4. Iterators
  5. Nullable types
  6. Private setters (properties)
  7. Method group conversions (delegates)
  8. Covariance and Contra-variance
  9. Static classes
C# 3.0

.NET Framework: .NET Framework 3.0\3.5

Visual Studio: Visual Studio 2008

Important Features:

  1. Implicitly typed local variables
  2. Object and collection initializers
  3. Auto-Implemented properties
  4. Anonymous types
  5. Extension methods
  6. Query expressions
  7. Lambda expressions
  8. Expression trees
  9. Partial Methods
C# 4.0

.NET Framework: .NET Framework 4.0

Visual Studio: Visual Studio 2010

Important Features:

  1. Dynamic binding (late binding)
  2. Named and optional arguments
  3. Generic co- and contravariance
  4. Embedded interop types
C# 5.0

.NET Framework: .NET Framework 4.5

Visual Studio: Visual Studio 2012/2013

Important Features:

  1. Async features
  2. Caller information
C# 6.0

.NET Framework: .NET Framework 4.6

Visual Studio: Visual Studio 2013/2015

Important Features:

  1. Expression Bodied Methods
  2. Auto-property initializer
  3. nameof Expression
  4. Primary constructor
  5. Await in the catch block
  6. Exception Filter
  7. String Interpolation
C# 7.0

.NET Framework: .NET Core 2.0

Visual Studio: Visual Studio 2017

Important Features:

  1. Out Variables in C#
  2. Pattern Matching in C#
  3. Digit Separators in C#
  4. Tuples in C#
  5. Splitting Tuples in C#
  6. Local Functions in C#
  7. Ref Returns and Ref Locals in C#
  8. Generalized Async Return Types in C#
  9. Expression Bodied Members in C#
  10. Thrown Expression in C#
  11. Async Main in C#
C# 8.0

.NET Framework: .NET Core 3.0

Visual Studio: Visual Studio 2019

Important Features:

  1. Default interface methods
  2. Nullable reference types
  3. Pattern matching enhancements
  4. Asynchronous streams / Asynchronous disposable
  5. Using declarations
  6. Enhancement of interpolated verbatim strings
  7. Null-coalescing assignment
  8. Static local functions
  9. Indices and ranges
  10. Unmanaged constructed types
  11. Readonly-Member
  12. Stackalloc in nested expressions
  13. Disposable ref structs
C# 9.0

.NET Framework: .NET 5.0

Visual Studio: Visual Studio 2019

Important Features:

  1. Top-level statements
  2. Record types
  3. Init-only setters
  4. Enhancements to pattern matching
  5. Natural-sized integers
  6. Function pointers
  7. Target type new
  8. Target type conditional
  9. Static anonymous methods
  10. Covariant return types
  11. Lambda discard parameters
  12. Attributes on local functions
C# 10.0

.NET Framework: .NET 6.0

Visual Studio: Visual Studio 2022

Important Features:

  1. Record structs
  2. Improvements in structure types
  3. Interpolated string handlers
  4. global using directives
  5. File-scoped namespace declaration
  6. Extended property patterns
  7. Improvements in lambda expressions
  8. Allow const interpolated strings
  9. Record types can seal ToString()
  10. Improved definite assignment
  11. Allow both assignment and declaration in the same deconstruction
  12. Allow AsyncMethodBuilder attribute on methods
  13. CallerArgumentExpression attribute
  14. 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.

C# 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.

  1. Cloud-native apps and services 
  2. Windows client applications
  3. Windows libraries and components
  4. Windows services
  5. Web applications
  6. Web services and Web API
  7. Native iOS and Android mobile apps
  8. Backend services
  9. Azure cloud applications and services
  10. Backend database using ML/Data tools
  11. Interoperability software such as Office, SharePoint, SQL Server, and so on.
  12. Artificial Intelligence and Machine learning
  13. Blockchains and distributed ledger technology including cryptocurrency
  14. Internet of Things (IoT) devices
  15. Gaming consoles and gaming systems
  16. Video games