C# Basic Interview Question
Q: what are different version of c# and their framework support ?
Ans : c#1.0 ,1.2,2.0,3.0,4.0,5. and 6.0 are different version of c# .
Frame work - dot net version
.Net Framework 1.0 = c#1.0 visual studio 2002
.Net Framework 1.1 = c#1.2 Visual studio 2003
.Net Framework 2.0 = c# 2.0 = visual studio 2005
.Net Framework 2.0 ,3.0, 3.5 = c#3.0 = visual studio 2008 , visual studio 2010
.Net Framework 4.0 = c#4.0 visual studio 2010
.Net Framework 4.5 = c#5.0 = visual studio 2012, 2013
.Net Framework 4.6 = c#6.0 = visual studio 2015
Q : what are method in c# ?
Ans : Method or function(will have return type) will be used for writing a programme in more manageable way ,
syntax for methods :
[attribute]
access-modifiers return type method name(parameter)
{
//body
}
Method can be declare in two type 1 : Instance 2 : Static ,
for declaring a method as static use keyword static in method e.g.
public static void hello()
{
// body
}
for static we do not need instance or can say new keyword for calling them in Main method ,that is also a static method .
Q : what the parameter we used in method ?
Ans : there are 4 types of parameter used in method
1: value type 2: reference type 3: out parameter 4: arrays type .
Q : what is difference between concrete class and abstract classes ?
Ans : concrete class and abstract class are same in all virtue except that abstract class can not be initiated while concrete class class can be initiated .
Q: How to declare array in c# ?
Ans : very Basic way of declaring a array is to use [] sign after your datatype eg int[]
array is basically used for storing similar type of values . suppose i want to store three integer type in array ,then we can write like this int[] x = new int[3] . now passed value to your integer by using
x[0] = 1 , x[1] = 23, x[2] = 56 . arrays always start from 0 . arrays are strongly typed means once you have defined x as integer , now you can not store string value in the array , also there is drawback of array once you have initiated array with defined value now you can not grow or decrease array area , like in our example you can not grow or decrease by 3 .
Q : How to write switch statement ?
Ans : Switch is basically an alternate to if ,else condition , if you do not want to check many condition through ,if else situation .
syntax for switch statement :
switch( input)
{
Case input1:
console.writeLIne (you have entered input1);
break;
case input :
console.writeLine(you have entered input);
break ;
default :
console.writelLIne(you have entered nothing);
break;
}
so in above case ,it will print "you have entered input" , default is necessary as last condition , break is also necessary after each condition to break the statement ,once it is satisfying condition .it will not go to next condition .
Q : how to use while condition in c# ?
Ans : syntax for while loop is
while(condition)
{
// do something ;
}
now suppose i want to print some values through while statement ,then it will look like this
int x = 0
while( x < 10)
{
console.write( x) ;
x = x+ 2 ;
}
so it will print like 0, 2 ,4 6,8
Q : how to use do while loop ?
Ans : in do while statement syntax :
do
{
//something
}while(condition)
like taking reference from above example ,
int x = 0 ;
do
{
console.Writeline (x) ;
x = x+ 2 ;
}while(x< 10)
the difference between ,while loop and do -while loop is that , in while condition if condition is false it will not execute statement, but in do-while at least a single time statement will executed if statement is false .
Q : what is foreach loop ?
Ans : for each loop can be used with arrays , collection ,generics ,arraylist to iterate though the items .
syntax for foreach loop
foreach (int x in array)
{
console.writeline (x) ;
}
so here it will print all stored values of array .
Q : What are interface in c# ?
Ans :
Interface are declared in c# by using interface keyword,
Interface allowed multiple inheritance .
For using interface a class must provide implementation of interface for using it .
A interface can inherit any other interface .
A interface is public by default . A
interface can not be used by creating a instance .
we can using a interface variable by assigning the child class who is inheriting interface mean interface i = new childclass();
Q : what are abstract classes ?
Ans :
Abstract Class can not not be initiated and only work like as base class .
Abstract class may contain abstract member .
Abstract can not be sealed class .
A class inherited from abstract must provide implementation by using override keyword to all inherited members .or declared abstract to self for using abstract class .
Q what are difference between abstract and interface ?
Ans :
1 : Interface can not have implementation ,while abstract class can have implementation .
2 : A interface can only be inherited by another interface ,while abstract class can be inherited by interface or abstract class as well .
3: Multiple inheritance is possible in interface while in abstract class it is not .
4: Interface is by default public ,while abstract class need access modifier .
Q : what are delegate ?
Ans :Delegate are function pointer , it is similar like method declaration except it used delegate keyword to self
Public delegate void iamdelegate(string test) ;
public static void delegate_method(string mssg)
{
console.write line (mssg) ;
}
so for using this delegate in main method ,you need to invoke delegate like
iamdelegate x = new iamdelegate(delegate_method) ;
x("Print this");
Ans : c#1.0 ,1.2,2.0,3.0,4.0,5. and 6.0 are different version of c# .
Frame work - dot net version
.Net Framework 1.0 = c#1.0 visual studio 2002
.Net Framework 1.1 = c#1.2 Visual studio 2003
.Net Framework 2.0 = c# 2.0 = visual studio 2005
.Net Framework 2.0 ,3.0, 3.5 = c#3.0 = visual studio 2008 , visual studio 2010
.Net Framework 4.0 = c#4.0 visual studio 2010
.Net Framework 4.5 = c#5.0 = visual studio 2012, 2013
.Net Framework 4.6 = c#6.0 = visual studio 2015
Q : what are method in c# ?
Ans : Method or function(will have return type) will be used for writing a programme in more manageable way ,
syntax for methods :
[attribute]
access-modifiers return type method name(parameter)
{
//body
}
Method can be declare in two type 1 : Instance 2 : Static ,
for declaring a method as static use keyword static in method e.g.
public static void hello()
{
// body
}
for static we do not need instance or can say new keyword for calling them in Main method ,that is also a static method .
Q : what the parameter we used in method ?
Ans : there are 4 types of parameter used in method
1: value type 2: reference type 3: out parameter 4: arrays type .
Q : what is difference between concrete class and abstract classes ?
Ans : concrete class and abstract class are same in all virtue except that abstract class can not be initiated while concrete class class can be initiated .
Q: How to declare array in c# ?
Ans : very Basic way of declaring a array is to use [] sign after your datatype eg int[]
array is basically used for storing similar type of values . suppose i want to store three integer type in array ,then we can write like this int[] x = new int[3] . now passed value to your integer by using
x[0] = 1 , x[1] = 23, x[2] = 56 . arrays always start from 0 . arrays are strongly typed means once you have defined x as integer , now you can not store string value in the array , also there is drawback of array once you have initiated array with defined value now you can not grow or decrease array area , like in our example you can not grow or decrease by 3 .
Q : How to write switch statement ?
Ans : Switch is basically an alternate to if ,else condition , if you do not want to check many condition through ,if else situation .
syntax for switch statement :
switch( input)
{
Case input1:
console.writeLIne (you have entered input1);
break;
case input :
console.writeLine(you have entered input);
break ;
default :
console.writelLIne(you have entered nothing);
break;
}
so in above case ,it will print "you have entered input" , default is necessary as last condition , break is also necessary after each condition to break the statement ,once it is satisfying condition .it will not go to next condition .
Q : how to use while condition in c# ?
Ans : syntax for while loop is
while(condition)
{
// do something ;
}
now suppose i want to print some values through while statement ,then it will look like this
int x = 0
while( x < 10)
{
console.write( x) ;
x = x+ 2 ;
}
so it will print like 0, 2 ,4 6,8
Q : how to use do while loop ?
Ans : in do while statement syntax :
do
{
//something
}while(condition)
like taking reference from above example ,
int x = 0 ;
do
{
console.Writeline (x) ;
x = x+ 2 ;
}while(x< 10)
the difference between ,while loop and do -while loop is that , in while condition if condition is false it will not execute statement, but in do-while at least a single time statement will executed if statement is false .
Q : what is foreach loop ?
Ans : for each loop can be used with arrays , collection ,generics ,arraylist to iterate though the items .
syntax for foreach loop
foreach (int x in array)
{
console.writeline (x) ;
}
so here it will print all stored values of array .
Q : What are interface in c# ?
Ans :
Interface are declared in c# by using interface keyword,
Interface allowed multiple inheritance .
For using interface a class must provide implementation of interface for using it .
A interface can inherit any other interface .
A interface is public by default . A
interface can not be used by creating a instance .
we can using a interface variable by assigning the child class who is inheriting interface mean interface i = new childclass();
Q : what are abstract classes ?
Ans :
Abstract Class can not not be initiated and only work like as base class .
Abstract class may contain abstract member .
Abstract can not be sealed class .
A class inherited from abstract must provide implementation by using override keyword to all inherited members .or declared abstract to self for using abstract class .
Q what are difference between abstract and interface ?
Ans :
1 : Interface can not have implementation ,while abstract class can have implementation .
2 : A interface can only be inherited by another interface ,while abstract class can be inherited by interface or abstract class as well .
3: Multiple inheritance is possible in interface while in abstract class it is not .
4: Interface is by default public ,while abstract class need access modifier .
Q : what are delegate ?
Ans :Delegate are function pointer , it is similar like method declaration except it used delegate keyword to self
Public delegate void iamdelegate(string test) ;
public static void delegate_method(string mssg)
{
console.write line (mssg) ;
}
so for using this delegate in main method ,you need to invoke delegate like
iamdelegate x = new iamdelegate(delegate_method) ;
x("Print this");
Comments
Post a Comment