C# Notes
C# Notes
NOTE
1. CLASSES - 1ST LETTER IS CAPITAL
2. METHODS - 1 ST LETTER IS CAPITAL
3. NAMESPACES - 1ST LETTER CAPITAL
4. KEYWORDS - SMALL LETTER
COMPILE
C.... PATH > CSC FILENAME.CS
RUN
C.... PATH > FILE NAME
console class by using this class we can perform all input/output operation on the
console
this class provide us various methods to perform i/o operations
this class is present in system namespaces
write()
writeLine()
Read()
ReadLine()
ReadKey()
Clear()
MSIL CODE
CLR
IF Statement
when you want to execute some specific code then you can use if statement.
if condition is true then if block will be executed oterwise else block will be
executed.
ELSE IF (LOOP)
when you want to execute some specific code then you can use ELSE if statement
CONSIDRING 1 OF THEM CAN BE TRUE FOR SAID CASE.
NESTED IF
IF 'IF' STATEMENT IS DEFINED WITHIN IF STATEMENT
EXAMPLE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
int pin,bal=2000;
Console.WriteLine("Enter ATM PIN....");
pin=int.Parse(Console.ReadLine());
if (pin == 777)
{
Console.WriteLine("welcoem to sbi....");
Console.WriteLine("Enter 1 for deposit\nEnter 2 for withdrwal\
nEnter 3 for balance Enquiry");
int opt = int.Parse(Console.ReadLine());
if(opt==1)
{ //deposit code here..
Console.WriteLine("Enter amount for deposit...");
int amt = int.Parse(Console.ReadLine());
bal = bal + amt;
}
else if(opt==3)
{ //balance enquiry
Console.WriteLine("Now Available balance is " + bal);
}
else
{
Console.WriteLine("invalid choice.....");
}
}
else
Console.WriteLine("invalid pin...");
Console.ReadKey();
}}}
FOR
DO WHILE
FOR EACH
FACTORIAL
INT T, I=1;
CONSOLE.WRITELINE(ENTER A NO);
T=INT.PARSE(CONSOLE.READLINE());
WHILE(T>=1)
{
I=I*T;
T--
}
CONSOLE .WRITELINE("FACTORIAL="+I);
for loop
BREAK KEYWORD
TROWS THE PROGRA CONTROL OUT OF LOOP
CAN BE USED IN LOOP'S AND SWITCH
while loop
when we don't know the no. of iterations then we use while loop
do while
RANDOM NO
Random random = new Random();
int X = random.Next(0000,99999);///(MIN VALUE, MAX VALUE)