Open In App

Introduction to C#

Last Updated : 23 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

C# is a general-purpose, modern and object-oriented programming language pronounced as “C sharp”. It was developed by Microsoft led by Anders Hejlsberg and his team within the .Net initiative and was approved by the European Computer Manufacturers Association (ECMA) and International Standards Organization (ISO). C# is among the languages for Common Language Infrastructure and the current version of C# is version 7.2. C# is a lot similar to Java syntactically and is easy for the users who have knowledge of C, C++ or Java. A bit about .Net Framework .Net applications are multi-platform applications and framework can be used from languages like C++, C#, Visual Basic, COBOL etc. It is designed in a manner so that other languages can use it. know more about .Net Framework Why C#? C# has many other reasons for being popular and in demand. Few of the reasons are mentioned below:

  1. Easy to start: C# is a high-level language so it is closer to other popular programming languages like C, C++, and Java and thus becomes easy to learn for anyone.
  2. Widely used for developing Desktop and Web Application: C# is widely used for developing web applications and Desktop applications. It is one of the most popular languages that is used in professional desktop. If anyone wants to create Microsoft apps, C# is their first choice.
  3. Community:The larger the community the better it is as new tools and software will be developing to make it better. C# has a large community so the developments are done to make it exist in the system and not become extinct.
  4. Game Development: C# is widely used in game development and will continue to dominate. C# integrates with Microsoft and thus has a large target audience. The C# features such as Automatic Garbage Collection, interfaces, object-oriented, etc. make C# a popular game developing language.

Beginning with C# programming: Finding a Compiler: There are various online IDEs such as GeeksforGeeks ide, CodeChef ide etc. which can be used to run C# programs without installing. Windows: Since the C# is developed within .Net framework initiative by Microsoft, it provide various IDEs to run C# programs: Microsoft Visual Studio, Visual Studio Express, Visual Web Developer Linux: Mono can be used to run C# programs on Linux. Programming in C#: Since the C# is a lot similar to other widely used languages syntactically, it is easier to code and learn in C#. Programs can be written in C# in any of the widely used text editors like Notepad++, gedit, etc. or on any of the compilers. After writing the program save the file with the extension .cs. Example: A simple program to print Hello Geeks 

Csharp




// C# program to print Hello Geeks
using System;
 
namespace HelloGeeksApp
{  
    class HelloGeeks
    {  
        // Main function
        static void Main(string[] args)
        {
 
            // Printing Hello Geeks
            Console.WriteLine("Hello Geeks");
 
            Console.ReadKey();
        }
    }
}


Output:

Hello Geeks

Explanation: 1. Comments: Comments are used for explaining code and are used in similar manner as in Java or C or C++. Compilers ignore the comment entries and does not execute them. Comments can be of single line or multiple lines. Single line Comments: Syntax:

// Single line comment

Multi line comments: Syntax:

/* Multi line comments*/

2. using System: using keyword is used to include the System namespace in the program. namespace declaration: A namespace is a collection of classes. The HelloGeeksApp namespace contains the class HelloGeeks. 3. class: The class contains the data and methods to be used in the program. Methods define the behavior of the class. Class HelloGeeks has only one method Main similar to JAVA. 4. static void Main(): static keyword tells us that this method is accessible without instantiating the class. 5. void keywords tells that this method will not return anything. Main() method is the entry-point of our application. In our program, Main() method specifies its behavior with the statement Console.WriteLine(“Hello Geeks”); . 6. Console.WriteLine(): WriteLine() is a method of the Console class defined in the System namespace. 7. Console.ReadKey(): This is for the VS.NET Users. This makes the program wait for a key press and prevents the screen from running and closing quickly. Note: C# is case sensitive and all statements and expressions must end with semicolon (;).

 Advantages of C#:

  • C# is very efficient in managing the system. All the garbage is automatically collected in C#.
  • There is no problem of memory leak in C# because of its high memory backup.
  • Cost of maintenance is less and is safer to run as compared to other languages.
  • C# code is compiled to a intermediate language (Common (.Net) Intermediate Language) which is a standard language, independently irrespective of the target operating system and architecture.
  • Simple and easy to learn: C# is designed to be an easy-to-learn language, especially for programmers familiar with languages like Java and C++. It has a clear syntax, which makes it easy to read and write code.
  • Object-oriented programming: C# is a fully object-oriented language, which allows developers to create reusable code and build complex applications with ease.
  • Large standard library: C# has a large standard library that includes a wide range of pre-built classes and functions. This makes it easy for developers to perform common tasks without having to write a lot of custom code.
  • Cross-platform support: C# can be used to develop applications for Windows, Linux, and macOS, and it can also be used to develop mobile and web applications.
  • Strongly typed: C# is a strongly typed language, which means that data types are checked at compile time. This helps to reduce errors and improve the reliability of code.
  • Integration with Microsoft technologies: C# is developed by Microsoft and integrates well with other Microsoft technologies, such as .NET, Azure, and Visual Studio.

Disadvantages of C#:

  • C# is less flexible as it depends alot on .Net framework.
  • C# runs slowly and program needs to be compiled each time when any changes are made.
  • Limited to Microsoft platforms: Although C# can be used to develop cross-platform applications, it is still primarily associated with Microsoft platforms, which limits its use in some contexts.
  • Garbage collection: C# uses automatic garbage collection to manage memory, which can lead to performance issues in some cases.
  • Learning curve for advanced concepts: While C# is easy to learn for basic programming concepts, it can be challenging to master some of the more advanced concepts, such as asynchronous programming or parallel processing.
  • Limited support for functional programming: While C# supports some functional programming features, it is primarily an object-oriented language and may not be the best choice for developers who prefer a functional programming style.

Applications:

  • C# is widely used for developing desktop applications, web applications and web services.
  • It is used in creating applications of Microsoft at a large scale.
  • C# is also used in game development in Unity.
  • C# can be used for developing machine learning applications using frameworks such as ML.NET. ML.NET provides tools for training and deploying machine learning models in C# applications.
  •  C# can be used to develop IoT applications using .NET IoT libraries. These applications can run on devices such as Raspberry Pi and Arduino.
  • C# can be used to create database applications using ADO.NET or Entity Framework. These applications can connect to various database systems, such as Microsoft SQL Server, Oracle, and MySQL.
  • C# can be used to develop cross-platform mobile applications using frameworks such as Xamarin and .NET MAUI. These applications can run on Android, iOS, and Windows devices.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads