C# (C Sharp) Introduction

What is C#

C# (C Sharp) is a simple, modern, easy, high-level, type-safe, and object-oriented programming language. C# is used to develop all types of applications.

What is C# used for

C# (C Sharp) was developed by Anders Hejlsberg. He is the lead architect of C# in Microsoft since the year 2000.

C# is used for all types of applications, for example, Web, Mobile, Console, Web API, Web Service, AI, Machine Learning, Game, etc.

There was a time when Sun (an old Java company) refused Microsoft to make changes in Java then Microsoft created, its own C# programming language. You can use C# for both platforms .NET Framework and .NET Core.

.NET Framework is tightly bound to the Windows operating system but to overcome this problem Microsoft developed .NET Core from the ground up. C# has a beautiful syntax and you can easily scale up design and architecture.

.NET Core is a cross-platform where you build and run applications for Windows, Linux, and macOS. C# is simple to understand than C, C++, and Java because it has inherited all the simple features from these three programming languages.

Features of C#

C# supports several features:

  • Type-Safe
  • Pattern matching
  • Easy to understand
  • Rich class library support
  • Lambda expression and LINQ
  • Supports object-oriented programming

There are so many C# concepts, when you deep dive into them, you will have a more clear idea about the topics. Here you will find beginners, intermediate and expert level C# concepts in these articles.

Advantages of C#

C# has many numerous advantages like:

  • Cross-Platform
  • Anonymous Type
  • Easy Development
  • Backward Compatibility
  • Auto Memory Management
  • Compile-Time error checking

Disadvantages of C#

  • Lack of a standalone compiler
  • Inflexible (for .NET Framework)
  • It takes more time to become an export
  • Can't interact directly with hardware and software

C Sharp program example

C#
    using System;
    class GreetReads
    {
        static void Main(string[] args)
        {
           Console.WriteLine("Hello World");
        }
    }

Output :

Output
    Hello World

Simple C# Program with Explanation:

Using

  • using is a directive. using directive is used to import types (class) defined in other namespaces (System).

System

  • The System is a namespace.

Class

  • class is a keyword. The name of the class start followed by the class keyword.

  • class is also known as a user-defined type in C#.

GreetReads

  • GreetReads is the name of the class.

Static

  • When a static keyword is used with the Main method that means, we can call the Main() without creating the object of GreetReads class.

Void

  • The void is a keyword, the meaning of void here is that the Main() doesn't return anything.

Main

  • It is an entry point of the program in C#. Main is called by common language runtime or CLR when the program is started.

string [ ] args

  • It is an array of strings in C#.

  • It is the parameter of the Main method and it can receive the data from the Command Prompt.

Console

  • It is a static class where WriteLine() method is present.

WriteLine

  • It is an inbuilt method that is used to print the output on the console window.

  • WriteLine() is a static method with a void return type.

Hello World

  • It is a simple string text in C# code.