C# Basic Interview Questions :-
1. What is C# ?
C# is a Microsoft language which is derived from C and C++. C# is a type-safe object oriented language, which is compiled by .Net framework.
2. What is the default type of for a class?
By default Class is a internal, if no access modifier is specified.
3. What is Inheritance?
When a class inherits or use the methods and properties of second class is called Inheritance. the first class is called as Base or parent class and class who inherits the properties is called derived or child class.
Inheritance is very useful in C# because of code re-usability . We can write method in base class and use the same function in other child classes.
4. What is Sealed Class?
Sealed class is a class which can not be inherited. by using sealed keyword we can restrict the class from to be inherited.
5. What is Abstract Method?
Abstract class is a class which can't be instantiated means we can not create a instance of a Abstract class. Abstract class must be inherits. Abstract class have abstract and non abstract methods. If all methods of a abstract class are abstract then it called a Pure Abstract class.
6. What is Interface?
Interface is mainly used for future planning. By using Interface we can perform Multiple inheritance in c#. Interface methods doesn't have any implementation, they only have definition.
7. What is the default type for a Interface?
By default Interface is internal.
8 . Difference between interface and Abstract class?
Abstract class methods have implementation where as interface methods only have a definition. A class can inherit only one abstract class but can implement many interfaces.
We can not create object of a Abstract class and also of a interface.
9. Difference between Dynamic and var?
C# compiler check the dynamic keyword at run-time whereas it checks the var at compile time.
Means if we doing anything wrong with var then compiler check this error at the time of compilation and our code will not run but if the same error with dynamic keyword the program will run successfully but at the run time it will throw error. Read more dynamic and var difference with Example
10. Difference between out and ref keyword?
Ref keyword will pass parameter as reference means when the value of parameter changed in called method then its values also get reflected in calling method.
The out keyword is also used to pass an argument like ref keyword, but the argument can be passed without assigning any value to it.
11. Can we use "this" keyword with Static Method?
No we can not use.
12. What is the difference between constant and readonly variables in C#?
Const keyword is used for making a variable value non changeable. We cannot modify the value
later in the code. While declaring constant variable Value assigning is mandatory.
Readonly variable value can be changed during run-time and we can assign value to readonly variales at the time of declaration or with in the constructor of the class. Read more
0 comments:
Post a Comment