hi in this article we will learn some important c# interview questions for beginners level these questions are given to you good confidence in basic
Why is “this” keyword used in C#?
this keyword makes code more clear and readable, it helps you share between data at block scope, static data, and instance data. we can’t use this keyword inside the static data
How many ways do we use this keyword?
- ‘this’ keyword used to call the current class members i.e field members or properties.
- ‘this’ keyword used to call the one constructor into another constructor in the same class.
What is Encapsulation?
Encapsulation means which binds the data and methods in a single unit (class).
What are the Advantages of using Encapsulation?
Data Hiding / Abstraction.
It makes the class simpler to use.
Which operator did we use to create an object?
by using new keyword wew ill create object
Where is the object Stored?
Heap is a memory place where the objects and its instance variable are stored.
What are the different types of variables in c#?
There are 3 kinds of variables
- Local variables
- Class/static variables
- Instance variables
What is the difference between an argument and a parameter?
The argument is the value/input that is passed while calling a method.
Parameters are the variable that is declared with method definition
How do you write a method with no return value in c#?
Use void as the datatype.
What is meant by static?
Irrespective of the object creation data will be allocated in memory and it is common for all the objects.
What are the different types of constructors?
Constructors can be divided into 5 types:
- Default Constructor
- Parametrized Constructor
- Copy Constructor
- Static Constructor
- Private Constructor
What are the different categories of Inheritance?
Inheritance can be classified to 5 types
- Single Inheritance
- Hierarchical Inheritance
- Multi-Level Inheritance
- Hybrid Inheritance
- Multiple Inheritance
What is the use of “as” Operator?
The “as” checks the type of a given object that is compatible with the new
object type. This keyword will checks whether the type of a given object is compatible with the new
object type. If it’s not compatible with the new one then it will return NULL.
What are the different types of polymorphism in C#?
There are two types of polymorphism in .net they are.
- Static polymorphism(Static binding).
- Dynamic polymorphism(Dynamic binding).
When the method cannot be overridden?
- Methods have a different return type
- Methods have a different access modifier
- Methods have a different parameter type or order
- Methods are nonvirtual or static
What is an interface?
An interface is nothing but contractor between two class, once we will inherit that class should be implemented All members in the derived class and is not possible to create an object of class because of incomplete behavior.
What is the Difference between concrete class vs abstract class?
1. we can create an instance as well as we can inherit.
2. No method should be abstract.
3. class hierarchy, the concrete class need not be on the first level.
1. Abstract class, We can not create an object but we can inherit.
2. In the application class hierarchy, an abstract class can be at the first level.
What is the Difference between Abstract and Virtual methods?
- abstract methods don’t contain anybody but virtual methods contain body
- the abstract class implements the abstract function in derived class but it is not necessary for virtual methods.
- an abstract method can only use in abstract class but it is not necessary for virtual methods.
- an abstract method is called pure virtual methods.
What is the difference between Array and ArrayList in C#.Net?
- The array is in C#.Net strongly typed its means it can store only specific types of data(items).
- Array stores a fixed number of elements.
- Size of anArray must be specified at the time of initialization.casting is not required of an array while retrieving because of the array are strongly type and specify the type of data items
- Use static helper class Array to perform different tasks on the array
- ArrayList can store any type of items elements.
- ArrayList grows automatically and you don’t need to specify size.
- ArrayList need to be cast to another data type while retrieving.
- ArrayList can include different utility methods for different tasks.
Can multiple catch blocks be executed?
No, Once the catch code executed, the control is transferred to the finally block, and then the code that follows the finallly block gets executed.
What is the difference between static, public, and void keywords?
Public: if we use a public keyword to variables or methods those members are accessible anywhere in the application.
Static: if we declared variables or methods are at a global level those members are accessible without creating an object of the class. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created.
void: void means it is the return type of method, but it does not return any value
What is an object in .net?
An object is nothing but an instance of a class. by using a new keyword we will create an object for class. if we will create an object for class memory will allocate in heap (object) memory will contain the information like the methods, variables, and behavior of that class.
What’s the difference between an interface and an abstract class?
- the interface is a pure prototype it means it has only declaration methods and members like abstract types.
- should be implemented All interface members in the derived class
- Not possible to create an object of the Interface but we will use it as a reference variable.
- An abstract class can have abstract methods, members and some concreate data also like properties.
- Not possible to create an object of the Abstract but we will use it as a reference variable.
Differences between Arrays And collections?
- We can’t insert a new element into the array
- We can’t delete any element from the array
- Array size is fixed.
- There is either insufficient memory no wastage of memory problem with in the array
- Array supports only single data types.
- Array doesn’t contain a data structure underlying to it.
- We can insert a new element into the collection anywhere then the following items will flush down automatically.
- We can delete any element from the collection then the following item will be flush up automatically.
- Collection size not fixed as long as memory is available we can add the elements.
- There is no insufficient memory of wastage of memory problem with collection
- Collection can store all the data type values default data type is an object.
- The collection contains a data structure underlying it.