You are on page 1of 9

C# Programming Language

 Basic Syntax:

using System;

namespace Helloworld;

class Program{
public static void Main(string[] args]{
Console.WriteLine(“Hello”);
}
}

 Output

WriteLine() : Displays the output by automatically giving new line

Write() : Provides no new line.

 Comments:

Single Line comments: //


Multiline comments: /* */

 Variables:

 int - stores integers (whole numbers), without decimals, such as


123 or -123
 double - stores floating point numbers, with decimals, such as
19.99 or -19.99
 char - stores single characters, such as 'a' or 'B'. Char values are
surrounded by single quotes
 string - stores text, such as "Hello World". String values are
surrounded by double quotes
 bool - stores values with two states: true or false

 Declaring Variables

type variableName = value;


 Constant keyword:

Keyword: const

 Display Variables:

To combine both text and a variable, use the + character:

string name = "John";

Console.WriteLine("Hello " + name);

The general rules for naming variables are:

 Names can contain letters, digits and the underscore character (_)
 Names must begin with a letter or underscore
 Names should start with a lowercase letter, and cannot contain
whitespace
 Names are case-sensitive ("myVar" and "myvar" are different variables)
 Reserved words (like C# keywords, such as int or double) cannot be used
as names
 Type Casting

 To read/input something

ReadLine(): Inputs the information from the user.


 C# Math functions:

o Math.Max(x,y)
o Math.Min(x,y)
o Math.Sqrt(x)
o Math.Abs(x)
o Math.Round(x)


 Different functions that can be done in a string

We can find the character using index


We can find the index of a character using IndexOf
We can form a Substring from existing character by Substring()

You might also like