C# interview questions for beginners

  .Net interview questions, C#

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?

  1. ‘this’ keyword used to call the current class members i.e field members or properties.
  2. ‘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.
Implementation Abstraction
It makes the class simpler to use.
Loose Coupling

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

  1. Local variables
  2. Class/static variables
  3. 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:

  1. Default Constructor
  2. Parametrized Constructor
  3. Copy Constructor
  4. Static Constructor
  5. Private Constructor

What are the different categories of Inheritance?

Inheritance can be classified to 5 types

  1. Single Inheritance
  2. Hierarchical Inheritance
  3. Multi-Level Inheritance
  4. Hybrid Inheritance
  5. 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.

  1. Static polymorphism(Static binding).
  2. Dynamic polymorphism(Dynamic binding).

When the method cannot be overridden?

  1. Methods have a different return type
  2. Methods have a different access modifier
  3. Methods have a different parameter type or order
  4. 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?

Concrete 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.

Abstract class
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?

  1. abstract methods don’t contain anybody but virtual methods contain body
  2. the abstract class implements the abstract function in derived class but it is not necessary for virtual methods.
  3. an abstract method can only use in abstract class but it is not necessary for virtual methods.
  4. an abstract method is called pure virtual methods.

What is the difference between Array and ArrayList in C#.Net?

Array

  1. The array is in C#.Net strongly typed its means it can store only specific types of data(items).
  2. Array stores a fixed number of elements.
  3. 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
  4. Use static helper class Array to perform different tasks on the array

ArrayList

  1. ArrayList can store any type of items elements.
  2. ArrayList grows automatically and you don’t need to specify size.
  3. ArrayList need to be cast to another data type while retrieving.
  4. 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?

Interface:

  1. the interface is a pure prototype it means it has only declaration methods and members like abstract types.
  2. should be implemented All interface members in the derived class
  3. Not possible to create an object of the Interface but we will use it as a reference variable.

Abstract:

  1. An abstract class can have abstract methods, members and some concreate data also like properties.
  2. Not possible to create an object of the Abstract but we will use it as a reference variable.

Differences between Arrays And collections?

Array:

  1. We can’t insert a new element into the array
  2. We can’t delete any element from the array
  3. Array size is fixed.
  4. There is either insufficient memory no wastage of memory problem with in the array
  5. Array supports only single data types.
  6. Array doesn’t contain a data structure underlying to it.

Collections:

  1. We can insert a new element into the collection anywhere then the following items will flush down automatically.
  2. We can delete any element from the collection then the following item will be flush up automatically.
  3. Collection size not fixed as long as memory is available we can add the elements.
  4. There is no insufficient memory of wastage of memory problem with collection
  5. Collection can store all the data type values default data type is an object.
  6. The collection contains a data structure underlying it.

Resource links:

C# technical Interview programs