- Features of asp.net 4.0 and 3.5
- Difference b/w == and equals in c#
- Optional parameters are supports in c#(yes)
- Close and dispose methods in c#
- Array list and hash table diff
- Types of hosting
- Types of contracts
- Was hosting
- How to implement wcf service
- How to implement method overloading in wcf
- How to pass data from one master page to another master page
- Popup window in asp.net
- In proc and out proc differences
- Query string( syntax)
- Query optimization
- union and union all difference
- Views and advantages
- Cursors(syntax)
- xmldocument inherits from
Latest CapGemini Interview Questions
Collections In C#.Net
Collection class provides Dynamic Operations, which is not possible in Regular Arrays
like Insert, Add, Clear, and Remove
All collection classes are available in System.Collection
Collection Classes are
ArrayList
Stack
Queue
Hash-table
like Insert, Add, Clear, and Remove
All collection classes are available in System.Collection
Collection Classes are
ArrayList
Stack
Queue
Hash-table
Difference between ArrayLst and HashTable
ArrayList
ArrayList is a liner data structure that hold items just like an array
Each element can be accessed with index
The size of the ArrayList object will increase dynamically based on requirement
It allows null values and duplicate values
we can store only similar type of data
Hash Table
Hash Table store data as key,value pairs
Each elements can be accessed with index/Key
it doesn't allow null and duplicate values
we can store different type of data
ArrayList is a liner data structure that hold items just like an array
Each element can be accessed with index
The size of the ArrayList object will increase dynamically based on requirement
It allows null values and duplicate values
we can store only similar type of data
Hash Table
Hash Table store data as key,value pairs
Each elements can be accessed with index/Key
it doesn't allow null and duplicate values
we can store different type of data
Diff b/w Abstract Class and Interface
Abstract Class
Abstract class is a class but not a complete class for creating object
So we can not create a object for Abstract classes
But a reference can be created
Abstract classes are also called as "Partial Abstract classes"
After creating Abstract class it can not be instantiated by itself
It must be inherited by child classes
Abstract class provides set of rules to implement next class
Rules will be provided by Abstract methods
Abstract methods does not contain any definition
While inheriting abstract class from child class all abstract methods must be override other that child class should be a abstract class
If a class contain at least one abstract method then it must be declared as "Abstract class"
Partial abstract class may contain function with body and function without body
If a class contains all functions without body then it is called as "Fully Abstract Class"
Interface
Interface is not a class
Interfaces supports multiple inheritance
Interfaces are implementable
In Interface all methods are abstract methods and by default public Access Modifier
A class can implement multiple interfaces
If a class has implement a interface that should be provide a implementation for all the methods
one interface can inherit another interface
Abstract class is a class but not a complete class for creating object
So we can not create a object for Abstract classes
But a reference can be created
Abstract classes are also called as "Partial Abstract classes"
After creating Abstract class it can not be instantiated by itself
It must be inherited by child classes
Abstract class provides set of rules to implement next class
Rules will be provided by Abstract methods
Abstract methods does not contain any definition
While inheriting abstract class from child class all abstract methods must be override other that child class should be a abstract class
If a class contain at least one abstract method then it must be declared as "Abstract class"
Partial abstract class may contain function with body and function without body
If a class contains all functions without body then it is called as "Fully Abstract Class"
Interface
Interface is not a class
Interfaces supports multiple inheritance
Interfaces are implementable
In Interface all methods are abstract methods and by default public Access Modifier
A class can implement multiple interfaces
If a class has implement a interface that should be provide a implementation for all the methods
one interface can inherit another interface
Basic Questions
Class
Object
diff b/w class and object
diff b/w two objects
Encapsulation
Abstraction
Data corruption
Constructor and types
void
Method
diff b/w method and constructor
splitup notation
shortcut notation
Gc
Memory leak
Access Modifiers
private
public
internal
protected
protected internal
static class
diff b/e static method and non-static method
static,constant and readonly
ploymorphism
Method overloading
Method overriding
Inheritance
base calss
derived class
base keyword
sealed class
Type compharison operator IS
Nested classes
diff b/w ref & out parameters
Finalize() and Dispose()
assert()
Debug class and Trace class
Do events have return type
can events have access modifiers
can we have shared events
what is shadowing
diff b/w class and strucutre
diff b/w Abstract class and interface
Object
diff b/w class and object
diff b/w two objects
Encapsulation
Abstraction
Data corruption
Constructor and types
void
Method
diff b/w method and constructor
splitup notation
shortcut notation
Gc
Memory leak
Access Modifiers
private
public
internal
protected
protected internal
static class
diff b/e static method and non-static method
static,constant and readonly
ploymorphism
Method overloading
Method overriding
Inheritance
base calss
derived class
base keyword
sealed class
Type compharison operator IS
Nested classes
diff b/w ref & out parameters
Finalize() and Dispose()
assert()
Debug class and Trace class
Do events have return type
can events have access modifiers
can we have shared events
what is shadowing
diff b/w class and strucutre
diff b/w Abstract class and interface
partial class in C#.Net
Partial class is introduced in .Net 2.0
partial class is a new way of defining class
it allows you to define a class into multiple partial classes
During compilation time compiler simply groups all partial classes into one class
partial classes should be preceded with Partial Keyword
All the partial classes should be defined in the same namespace
Method signature should be unique
partial class is a new way of defining class
it allows you to define a class into multiple partial classes
During compilation time compiler simply groups all partial classes into one class
partial classes should be preceded with Partial Keyword
All the partial classes should be defined in the same namespace
Method signature should be unique
Diff b/w String and String Builder in C#.Net
Strings:
String s="Santhosh"
String Builder:
- Strings are internally represented as character array
- System namespace contains a class string
- System.String class is used to work with string litter ls
- String litterls are nothing but a Sequence of Characters these are enclosed with double quotes
- when we want to use string methods every time we have to create string object in the memory
- so it will degrade the performance of application
- strings are immutable means,value cant be changed
String s="Santhosh"
String Builder:
- String Builder is mutable means,value can be changed
- when we want to modify a string using string builder no need to create object
- it will improves the performance of application
Boxing and Unboxing in C#.Net
Boxing: Boxing is the process of converting value types to reference types
int x=10
Object obj=x; //Boxing
UnBoxing: Unboxing is the process of extract the values from objects
Object obj=x; //Boxing
int y=(int) obj; //Unboxing
int x=10
Object obj=x; //Boxing
UnBoxing: Unboxing is the process of extract the values from objects
Object obj=x; //Boxing
int y=(int) obj; //Unboxing
Diff b/w Class and Structure?
- Both can have Constructors,Methods,Properties,Fields,Constants,Enumerations,Events,Delegates and Event Handlers
- Both can have Constructors with or with out parameters
- Both can implement interfaces
- Classes are reference type so stored in heap memory
- Structures are value types so stored in stack memory
- Class members can be declared as Protected
- Structure members can't be created as Protected
- We can do inheritance in classes
- we can't do inheritance in structures
Access Modifiers in C#.Net
Access Modifiers are used to control what our class objects can access its own fields or methods if they are created in some other classes
public fields or methods is accessible from all classes every where
Private:
Private fields or methods is accessible only with in its own class
Internal:
Internal fields or methods is accessible from all classes defined in the same assembly
Protected:
Protected fields or methods can be accessed by its objects with in the same class or derived classes
Protected Internal:
Protected fields or methods can be accessed by its objects in all classes with in the same assembly or by derived classes from other assembly
- Public
- Private
- Internal
- Protected
- Protected Internal
public fields or methods is accessible from all classes every where
Private:
Private fields or methods is accessible only with in its own class
Internal:
Internal fields or methods is accessible from all classes defined in the same assembly
Protected:
Protected fields or methods can be accessed by its objects with in the same class or derived classes
Protected Internal:
Protected fields or methods can be accessed by its objects in all classes with in the same assembly or by derived classes from other assembly
Diff b/w Ref & Out parameters in C#.Net
Out Parameter:
Variable gets value initialized after going into the method, Later the same value is returned to the main method
EX:
namespace outPar{
class outref
{
static void Main(string[] args)
{
yyy a = new yyy(); ;
// u can try giving int i=100 but is useless as that value is not passed into
// the method. Only variable goes into the method and gets changed its
// value and comes out.
int i;
a.abc(out i);
System.Console.WriteLine(i);
}
}
class yyy
{
public void abc(out int i)
{
i = 10;
}
}
}
OutPut:
10
Ref Parameter:
Variable should be initialized before going to the method,Later the same value or modified value
will be return to the main method
Ex:namespace refPar
{
class outref
{
static void Main(string[] args)
{
yyy a = new yyy(); ;
int i = 0;
a.abc(ref i);
System.Console.WriteLine(i);
}
}
class yyy
{
public void abc(ref int i)
{
System.Console.WriteLine(i);
i = 10;
}
}
}
OutPut:
0
10
Diff b/w Static,Constant and Readonly
Static: Value can be initialized once
Constant: Value can not be changed
initialization must be at compile time
Readonly: Value can be initialized only once from the constructor of a class
initialization can be at run time
EX:
Constant: Value can not be changed
initialization must be at compile time
Readonly: Value can be initialized only once from the constructor of a class
initialization can be at run time
EX:
class Manager { readonly DateTime _startup; // the readonly field public Manager() { // Initialize startup time. this._startup = DateTime.Now; } public DateTime GetStartup() { // We cannot modify the DateTime here. return this._startup; } }
class Program
{
static void Main()
{
Manager manager = new Manager();
Console.WriteLine(manager.GetStartup());
}
}
OutPut:
Current time
Diff b/w Method and Constructor?
- Method will be used after creating object
- Constructor will be used while creating object
- Constructor will be used only once for the object
- Method will be used n no of times lifetime of the object
Constructors?
Constructor:
Constructor looks like a method
constructor may not have return type
constructor name same name as the class name
constructor will be used while creating the object
with out creating object we cant create object
"Constructor is a place for defining Business Rules these rules should be applied while creating the object"
Types of Constructors:
we have 3 types of constructors
It is a special instance constructor
To initialize the static data
If a class has one or more private constructors and their is no public constructors then other class(Except Nested class)are not allowed to create instance of this calss
Ex:
public sealed class PrivateConstuctor
{
public static readonly PrivateConstuctor Instance = new PrivateConstuctor();
public int A;
private PrivateConstuctor()
{
this.A = 5;
}
class TestProgram
{
static void Main()
{
PrivateConstuctor obj = PrivateConstuctor.Instance;
Console.WriteLine(obj.A);
obj.A++;
Console.WriteLine(obj.A);
}
}
}
OutPut:
5
6
Static Constructor:
It is used to initialize any static data
To perform a particular action that needs to be performed once only
It is called automatically before the first instance is created or any static members are referenced
static constructors may not have parameters
their is no access modifier to define the static constructor
it cannot be called directly
it is useful when creating wrapper classes for unmanaged code,when the constructor can call LoadLibrary method
Copy Constructor:
Constructor looks like a method
constructor may not have return type
constructor name same name as the class name
constructor will be used while creating the object
with out creating object we cant create object
"Constructor is a place for defining Business Rules these rules should be applied while creating the object"
Types of Constructors:
we have 3 types of constructors
- Private Constructor
- Static Constructor
- Copy Constructor
It is a special instance constructor
To initialize the static data
If a class has one or more private constructors and their is no public constructors then other class(Except Nested class)are not allowed to create instance of this calss
Ex:
public sealed class PrivateConstuctor
{
public static readonly PrivateConstuctor Instance = new PrivateConstuctor();
public int A;
private PrivateConstuctor()
{
this.A = 5;
}
class TestProgram
{
static void Main()
{
PrivateConstuctor obj = PrivateConstuctor.Instance;
Console.WriteLine(obj.A);
obj.A++;
Console.WriteLine(obj.A);
}
}
}
OutPut:
5
6
Static Constructor:
It is used to initialize any static data
To perform a particular action that needs to be performed once only
It is called automatically before the first instance is created or any static members are referenced
static constructors may not have parameters
their is no access modifier to define the static constructor
it cannot be called directly
it is useful when creating wrapper classes for unmanaged code,when the constructor can call LoadLibrary method
public class Bus
{
// Static constructor:
static Bus()
{
System.Console.WriteLine("The static constructor invoked.");
}
public static void Drive()
{
System.Console.WriteLine("The Drive method invoked.");
}
}
class TestBus
{
static void Main()
{
Bus.Drive();
}
}
OutPut:
The static constructor invoked.
The Drive method invoked.
If we want to create a new object and want to copy the values from existing object is called copy constructor
class Person
{
private string name;
private int age;
public Person(Person PreviousPerson)
{
name = PreviousPerson.name;
age = PreviousPerson.age;
}
public Person(string name, int age)
{
this.name = name;
this.age = age;
}
public string Details
{
get
{
return name + " is " + age.ToString();
}
}
}
class CopyConstructor
{
static void Main()
{
Person person1 = new Person("Santhosh",25);
Person person2 = new Person(person1);
Console.WriteLine("Person2 Details:" +person2.Details);
}
}OutPut:Person2 Details: Santhosh is 25
Object Oriented Programming(OOPs)
Encapsulation:
It is the process of hiding all the internal details of objects from the outside world
Abstraction:
It talks about hiding the complexity of code by providing set of interfaces to consume the functionality
Hiding the unnecessary things and revealing when it needs
Inheritance:
Reusing parent class variables and method along with child class variables and methods will be used while creating the child object is called "Inheritance"
Base class
Derived class
Base class: The class which is allowing others to inherit fields or methods is called "Base class"
Derived class: The class which is inherited fields or methods from other class is called "Derived class"
What is the use of Inheritance:
Using Inheritance concept reduce the development time and better maintenance
Polymorphism:
Having multiple forms
To ability to appear in many forms
same operation may behave differently on different classes
We have two types
- Compile time polymorphism(Method overloading)
- Run time polymorphism(Method overriding)
Method Overloading:
The methods with in the class can have the same name but different in their parameter list and return type
Ex: class A
{
public void Add()
{}
public int Add()
{}
public void Add(int x)
{}
}
Method Overriding:
If a method of parent class redefining under its child classes with the same signature
Ex:
class BC
{
public virtual void Display()
{
System.Console.WriteLine("BC::Display");
}
}
class DC : BC
{
public override void Display()
{
System.Console.WriteLine("DC::Display");
}
}
class Demo
{
public static void Main()
{
BC b = new BC();
b.Display();
DC d = new DC();
d.Display();
BC dd = new DC();
dd.Display();
Console.ReadLine();
}
}
output :
BC : Display
DC : Display
DC : Display
Without Method Overriding
BC : Display
DC : Display
BC : Display
About Class and Object?
Class: Class is a plan of software object our computer is going to create
Class is having three types of meanings
1.Actual Meaning
2.Design Meaning
3.Usage Meaning
Actual Meaning:
class is a plan of software object our computer is going to create
class is a logical representation(Imaginary representation)
Design Meaning:
Grouping smiler variables and methods doing so called classification
Usage Meaning:
it is a user defined data type,it is also called as complex data type bcoz it contains multiple variables and methods
Object:
It is a physical representation of a class(Actual representation)
software objects represented in the computer memory is called RAM
Diff b/w Class and Object:
Class is a logical representation(Imaginary representation)
Object is a physical representation(Actual representation)
Diff b/w two objects:
Two objects in the computer memory differentiated by their memory locations or memory address
software objects nothing but a Real-Time objects in the computer memory
For any given class we can create n no of objects depends on the availability of computer memory
Subscribe to:
Posts (Atom)




