Saturday, January 14, 2012

Operators ,Expressions and Statements

Operators ,Expressions and Statements

==> Statements - are complete sentences in C#
==> Statements are made up of one or more expressions .
==>Expressions contains operators and operands.

eg 1. Console.writeline("Type some numbers");

In the above example,
1. Console.writeline("Type some "numbers"); -whole thing is called expression.
2. Console and "type some numbers" are operands .

eg 2. a= b+5;
==> here "b+5" is the expression.
==> b is the operand and "+" is the operator.

eg 3. if(a==3)
==> if(a==3)- the whole thing is statement.
==> (a=3)is the expression

eg 4. myString = "john" + myLastName
==> "john" + myLastName is the expression .
==> john and myLastName are the operands and + is the operator.


Operands - can be objects , variables, or literal strings.
Operator - can be addition (+),concatenation (+), assignment (=), equality(==).

==>The operator for method invocation is (). This is what we use to pass our arguments to the parameters of the given method .
eg: Console.WriteLine(" hai "); and Console.ReadLine();

==> Dot operator(.) - which is for member access,that is , to access a method which is a member of a class .
eg: Console.WriteLine("hai"); -here writeline is the method and console is a class.

==>Declaration Statement
eg: int x;

==> Declaration Statement with initialization
eg: int x=3 ;

==> Expression statement
eg: myString = "john" + myLastName

==>Selection(Decision) Statement
eg: if(a>b)c = "myName"; - that if "a>b" then c is equal to "myName"

==>post-increment (x++),post-decrement (x--), pre-increment (++x) and pre-decrement (--x) operators
eg: suppose that int x= 0; then apply ++x,--x, x-- and x++

++x ==> 1 , --x ==> 0 , x-- ==> 0 and x++ ==> 1.

==>AND(&&) and OR(||) operators - These two are known as Logical Operators.
eg:1. if ( isTrue == false && isFalse == false )
{
// code block
}
You use the AND operator when you want to check more than one value at once. So in the example above, you're checking if both values are false. If and ONLY if both of your conditions are met ,then the code block get executed.

eg;2. if ( isTrue == false || isFalse == false )
{
// code block
}
If just one of our condition is false, then the code block will get executed.



Operators with their precedence and Associativity





Naming Conventions
A consistent naming pattern is one of the most important elements of predictability and discoverability in a managed class library. Widespread use and understanding of these naming guidelines should eliminate unclear code and make it easier for developers to understand shared code.

There are three types of capitalization styles defined:

1. Camel Case - The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.
eg: myFirstName, numberOfDays etc.
Most programmers use this . Its a way to easily read something.

2. Pascal Case - The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.
eg; DataType , DataSet etc.

3. Uppercase - all letters are capitalized.
eg; ADO, ID etc.

No comments:

Post a Comment