0% found this document useful (0 votes)
2 views

c# interview questions

Uploaded by

Ravi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

c# interview questions

Uploaded by

Ravi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1) What is c#?

C# ia is object oriented programming language, used to develop various types of applications


like windows based applications, web based applications, desktop applications..

2) What is a constructor?
A constructor is a special method, present under a class responsible for initializing the variables
of that class.

3) What is ref and out parameters?


Ref and Out parameters are used to return two values as result. We have to pass ref or out
parameters as an argument to a method. Ref parameters have to be initialized before passiing
where as out parameters no need to initialized.

Ex: public int Math(int a , int b, ref c, out d)


{
c = a+b;
d = a*b;
}
Static void main(string[] args)
{
Int m= 20; n= 50;
Program p= new Program(); //creating object for program class
Int c=0; d; //ref parameter have to initialized
P.Math(m,n,ref c,out d);
}

4) Using keyword in c#?


2 ways we use using
1. Using directive - used to import all types from a single namespace to use in code without
specifying fully qualified namespace

Ex: using System;


Console.writeline(“Hello”);
If not using system namespace
System.Console.writeline(“Hello”);

2. Using statements - to ensure correct use of IDisposal objects. Means ensure memory garbage
collection action is properly executed after method job done.(ensure that the dispose method
is triggerd correctly at the end of the using block).

Ex: if we use straemwriter and streamreader to open a file and read data. If we didn’t close file
we will getfile is access by another process.
In this case use statements are used
using(streamwriter st = new streamwriter(“test.txt”);
{
Console.writeline(datetime.now.tostring());
}
using(streamreaderr st = new streamreader(“test.txt”);
{
Console.writeline(st.readline());
}
5) What is serialization?
Serialization is the process of converting object in to stream of bytes or plain text data.
Deserailization is the process of converting back from serialized data stream into original object.
Serialization stores the state of object.

Namespaces used

 System.Runtime.Serialization
 System.Runtime.Serialization.Formatters.Binary

6) This keyword not used in static method why?


This refer to current instance/object of the class. For staticclass we can not create instance,
Hence we can notuse this in static.\ class/method.

7) C# code compilation?
* Source code compilation in managedcode
* Newly created code is clubbed with Assembly code
* CLR is loaded
* Assembly execution is done through CLR

8) What is oops?
Object oriented programming helps us to think in terms of realworld entity.

9) What is class and object?


CLass is a type or blue print, it contains mthod and properties. Objectis an instance of a class.

10) OOPS concepts?


Abstraction - shows only what is necessary. Abstraction happens at the time of designing time.
User can decide have to declare public or private properties.
Encapsulation - hide complexity. Encapsulation implements abstraction. ENcapsulation happens
at the time of executing code.
Encapsulation and abstraction complements each other.
Inheritence - parent child relationship between two classes.. Parent class properties can access
in child class.
Polymorphism - Object acts differently under different conditions.
2 types.
1. Static polymorphism - implemented by method overloading
2. Dynamic polymorphism - implemented by method overriding.
These 2 happens in parent child relationship.

11) What is Virtual keyword?


Virtual keyword helps us to define some logic in the paent class which can be overridden in
child class.

12) Mthod overloading


Method with same names with different signatures

13) Mthod overriding


Using virtual keyword we can override method in child class.

14) OPerator overloading


Operaator overloading is the concept of polymorphism where we cam redefine operators like
plus, minus, multiplication sign with additonal functionalities.

15) What is abstract class?


Abstract class is partially defined parent class. Can create using abstract keyword before class.
Some have implemenation and some have partially defined, they can implement in child class.
Abstract class we can not create instance.

16) Interface
An interface is a contract it’s a legal binding between who is developing the class and who is
consuming the class.
OR
Interface is a contracr, by having contract we have better control over control on impact
analysis, change management and breaking changes.
All properties and methods in interface are public.
Method implentation can be achieved using child class.
* Multiple inheritence helps to add new methods without affecting the old interfaces.
* We can not create instance of interface

You might also like