By default it will show the recent post/content added.
To read from starting....Click Here
See "ChapterWise Posts" right side for complete list.

Monday, 20 April 2015

C# Instructions

Types of C# Instructions:
  1. Type Declaration
  2. Arithmetic
  3. Control
  4. Exception Handling
  5. Advanced













The following statements would work.

int a,b,c,d;
a=b=c=d=10;
int d=67,g=98;
float k=7.8f,r=k+3.1f;

But not below.

int a=b=c=d=10;//trying to use b,c,d before defining them.
float b=a+3.1f,a=1.5f; //trying to use a before defining it.

In an arithmetic expression, if both real and integer types are there, then the final result will be implicitly converted to real type.

But even though the expected result is real for an expression having all integers, the decimal will be truncated. So we need to convert it explicitly.
Ex: float a=(float)6/4;

Hierarchy of Operations.










Within the parenthesis same hierarchy will be given precedence.

If we want to prevent user from changing the variable, we can define it as constant. They must be defined and initialized simultaneously.
const float pi=3.14f;
const float pi; pi=3.14f; //will give error.

ReadLine() and Read() à used for getting input from console.
Convert.ToChar() to convert data read to character from string.Similary other methods are there in Convert class.

We can insert variables in the middlwe of WriteLine() and Write() using format specifiers.
Ex: Console.Write(“Avg={0:d}\nPercentage={1:f}”,avg,per);













\n is an escape sequence which is mentioned above example.These characters have special meaning in the string when they keep in program.











In control instructions there are 4 types(sequential, selection or decision control, repetition or loop control, case control).

We will discuss about them in next post.

No comments:

Post a Comment