Introduction

C# is a programming language developed by Microsoft.

C# is used in many fields , Some of them are:-

  1. Desktop App Development
  2. Mobile App Development
  3. Game Development
  4. Backend Web Development

C# is one of the most popular programming languages , Because:-

Syntax

Syntax is the structure of statements , Here is a simple program typed in C# to discuss the meaning of syntax

using System;
namespace Hello
{
    class MyProgram
    {
        static void Main(string[] args)
        {
            /* That is my first program
            I created it today*/
            // Printing text to console and filling the rest of that line
            Console.WriteLine("Hello World!");
            // Printing text to console without filling the rest of that line
            Console.Write("Hello ");
            Console.WriteLine("AAA");
        }
    }
}
Data Types

Some data types that are supported by C# :-

  1. integer (int) ... 1 , 500 , -200
  2. double (double) ... 0.5 , 3.14 , -2.5
  3. string (string) ... "AAA" , "What is your name ?"
  4. character (char) ... 'A' , '+' , '5'
  5. boolean (bool) ... true , false
Variables

Variables are containers for storing data values.

The syntax for declaring a variable and assigning a value to it is as following :

data-type variable-name = value(data) ;

For example :-

int age = 20 ;
string FirstName = "AAA" ;
string full_name = "AAA BBB" ;
double _degree = 80.5 ;
char grade = 'A' ;
bool student = true ;
bool male = true ;
Type Casting

Type casting means turning a certain data from a type to another one.

Syntax for type casting is :-

(data-type) data

For example :-

double pi = 3.14 ;
int myInt = (int) pi ;
Console.WriteLine(pi) ; // 3.14
Console.WriteLine(myInt) ; // 3
User Input

You already know that Console.WriteLine() is used to output text.

Now you are going to learn how to use Console.ReadLine() to get user input.

Console.ReadLine();

For example :-

int age ;
Console.Write("Enter your age:") ;
age = Console.ReadLine() ;
Console.WriteLine("You are " + age + " years old") ;
Booleans

Booleans are data types that can be used to control whether something is true or false(yes or no / on or off).

bool male = true ;
bool student = true ;
bool permission_accepted = false ;