c# interview questions
c# interview questions
2) What is a constructor?
A constructor is a special method, present under a class responsible for initializing the variables
of that class.
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
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.
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