Wednesday, 19 February 2014

Operators and Expressions Questions in C#(Asp.Net)

1. ) What is an operator in C#?
An operator is a symbol that is used to perform certain Mathematical and Logical  manipulations.  operators are used in program to manipulate data and variables.


2. ) What are  Special operators in C#?
is                                         Relational operator
as                                        Relational operator
typeof                               type operator
sizeof                                size operators
new                                    object creator
.(dot)                                 member-access operator
checked                            overflow checking
unchecked                       overflow checking

3. ) What are the shorthand assignment operators in C#?
  • x+=1
  • x-=1
  • x*=n+1
  • x/=n+1
  • x%=y
4. ) What is advantages of  shorthand assignment operators in C#?
  • The statement is more concise and easier to read.
  • It is more easier to write.
  • The use of shorthand operators result is a more efficient code.
5. ) What is type of conversion in C#?
  • Implicit conversion
  • Explicit conversion
6. ) What are the Increment and Decrement operators  in C#?
  • x++
  • x--
  • ++x
  • --x
7. ) What is implicit conversion  in C#?


     1. ) Implicit Conversions:
Implicit conversions are those that can always be performed without any loss of data.In implicit conversion we can convert only short range type values to long range type values.C# does this conversion automatically .But reverse is not true.Because short range type is the subset of long range type so that no data will be lost in implicit conversion.
Ex. short x= 10;
int y = x ;          is true
short z = y ;  is not true(reverse is not true)
  8. ) What is Explicit conversion  in C#?
  2. ) Explicit Conversions:-
Explicit conversions are those that convert long range type values to short range type values.In this type of conversions data will be lost.Because here we convert long range type to short range type.This is known as casting.
Ex.
       int to short
         uint to ushort
         long to int
         float to long
         double to long

Syntax:
type variable 1 = (type) variable 2 ;

Ex. 1:
int x = 25 ;
short y = (short) x ;
Ex. 2
float f = 15.0f ;
long l = (long ) f ;
Ex. 3
int x = 10 ;
string s = x. ToString();
Ex. 4
string s = "25";
int x = int.Parse(s);
int y = x + 5 ;
Output: 30
Ex. 5
int x = 25 ;
int y = 10 ;
short z = (short)x/(short)y ;
Difference between Int.Parse() and Convert.ToInt32():-
Int.parse():- This used only for convert the string values to the integer values.
Ex.
String s = "50";
int x = s + 5 ;
output: 55
Convert.ToInt32():-This is used for convert the any type of values to the integer values.
Ex. 1
Object o = 25 ;
int x = Convert.ToInt32(O) + 10;
Output
x  = 35
Ex2
string s = "25";
int x = Convert.ToInt32(s) + 10;
output:
x = 35 



9. ) What is mixed mode Arithmetic in C#?
When one of the operands is real and the other is integer then that expression is called a mixed-mode arithmetic.

10. ) What is an Expression in C#?
An Expression is a statement that is evaluated by the compiler or  human.
Ex.
variable=Expression;

0 comments:

Post a Comment

Get Benifits