Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

May 11, 2022

Top 20 C# Language Interview Questions and Answers


        Microsoft's C# is an object-oriented programming language. The.NET framework uses C# to create websites, applications, and games. C# is popular for a variety of reasons. C# is described as being easier to learn than other programming languages. You're more likely to construct online applications or gaming apps with C#. Automatic garbage collection, interfaces, and other features in C# enable developers create better apps.

Collaboration with Microsoft gives C# applications an advantage since they can reach a broader audience. Because C# is such a popular programming language, many large and small businesses utilise it to build their products. So, to ace the interviews, prepare yourself with basic and advanced level C# questions.

BlockChain interview Questions and Answers

Ques. 1): Is it possible to run several catch blocks?


No, you cannot execute multiple catch blocks of the same type. Control is handed to the finally block after the correct catch code has been completed, and then the code that follows the finally block is executed.

C language Interview Questions and Answers

Ques. 2): What exactly are the distinctions between public, static, and void?


Anywhere in the application, public stated variables or methods are accessible. Without generating an instance of the class, static declared variables or methods are globally available. The type of access modification used determines whether or not static members are globally available by default. The method's address is saved as the entry point, and the compiler utilises this information to start execution before any objects are generated. And Void is a type modifier that indicates that the method or variable returns nothing.

C++ language Interview Questions and Answers

Ques. 3): In C#, what is garbage collection?


Garbage collection is the process of releasing memory held by undesirable things. When you create a class object, some heap memory space is automatically allocated to the object. After you've completed all of the activities on the item, the memory space it takes up becomes wasted. Memory must be made available. Garbage collection occurs in three situations:

  • If the occupied memory by the objects exceeds the pre-set threshold value.
  • If the garbage collection method is called
  • If your system has low physical memory

Machine Learning Interview Questions and Answers

Ques. 4): Define Constructors in  C#.


A function Object() { [native code] } is a member function that has the same name as the class it belongs to. When an object class is created, the function Object() { [native code] } is called automatically. While initialising the class, it constructs the values of data members.

MySQL Interview Questions and Answers

Ques. 5): What exactly are Jagged Arrays?


The array with array elements is known as a jagged array. The elements can be of various shapes and sizes. An Array of arrays is another name for jagged Array.

PHP Interview Questions and Answers

Ques. 6): What is the difference between Custom Control and User Control?


Custom Controls are compiled code (Dll) controls that are easier to use and may be added to the toolbox. Developers can add controls to their web forms by dragging and dropping them. At design time, attributes can be used. Custom controls can be simply added to multiple applications (If Shared Dlls). If they are private, we can copy the dll to the web application's bin directory, add a reference, and use them.

User Controls are comparable to ASP include files in that they are simple to construct. It is not possible to drag and drop user controls into the toolbox. They have their own code and design. Ascx is the file extension for user controls.

PowerShell Interview Questions and Answers

Ques. 7): What’s the difference between the Array.CopyTo() and Array.Clone()?


The Clone() method copies an array shallowly. A shallow copy of an Array duplicates only the elements of the Array, regardless of whether they are reference or value types, but not the objects to which the references link. The references in the new Array point to the same objects as the previous Array's references.

The Array class's CopyTo() static function copies a piece of one array to another array. The CopyTo method transfers all of an array's items to a new one-dimensional array. Listing 9 shows how to copy the contents of an integer array to an array of object types.

Python Interview Questions and Answers

Ques. 8): In C#, what are the different types  of classes?


A class is a logical unit that contains all of the properties of its objects and instances. There are four sorts of such classes in C#:

Static type: The keyword'static' defines a class that does not allow inheritance. As a result, you won't be able to construct an object for a static class.

static class classname 


  //static data members 

  //static methods 


Partial class: Partially divided or shared source (.cs) files are possible with the partial class, which is defined by the term 'partial.'

Abstract class: Abstract classes are classes that cannot be instantiated and cannot be used to construct objects. Abstract classes are based on the OOPS abstraction idea. Abstraction aids in separating important details from those that aren't.

Sealed class: A sealed class is one that can't be inherited. To prevent users from inheriting that class, use the keyword sealed.

Python Pandas Interview Questions and Answers

Ques. 9): What is IEnumerable<> in C#?


 IEnumerable is the parent interface for all non-generic collections in System.Collections namespace like ArrayList, HastTable etc. that can be enumerated. For the generic version of this interface as IEnumerable<T> which a parent interface of all generic collections class in System.Collections.Generic namespace like List<> and more.

 In System.Collections.Generic.IEnumerable<T> have only a single method which is GetEnumerator() that returns an IEnumerator. IEnumerator provides the power to iterate through the collection by exposing a Current property and Move Next and Reset methods if we don’t have this interface as a parent so we can’t use iteration by foreach loop or can’t use that class object in our LINQ query.

SQL Server Interview Questions and Answers

Ques. 10): In C#, what are extension methods? How may extension techniques be used?


Extension methods allow you to add methods to existing types without having to create a new derived type, recompile it, or modify it in any way.

An extension method is a form of static method that is referred to as if it were an instance method on the extended type.

A static method of a static class with the "this" modifier appended to the first parameter is called an extension method. The extended type will be the type of the first parameter.

Extension methods are only in scope if you use a using directive to explicitly import the namespace into your source code.

Unix interview Questions and Answers

Ques. 11): What makes the System.String and System.Text.StringBuilder classes different?


System.Strings are unchangeable. When we change the value of a string variable, the existing memory allocation is released and fresh memory is allocated to the new value. System. StringBuilder was created with the idea of a mutable string that can be used for a number of operations without requiring a separate memory address for the updated string.

Ques. 12): What are Generics in C#?


In C# collections, defining any kind of object is termed okay which compromises C#’s basic rule of type-safety. Therefore, generics were included to type-safe the code by allowing re-use of the data processing algorithms. Generics in C# mean not linked to any specific data type. Generics reduce the load of using boxing, unboxing, and typecasting objects. Generics are always defined inside angular brackets <>. To create a generic class, this syntax is used:

GenericList<float> list1 = new GenericList<float>();

GenericList<Features> list2 = new GenericList<Features>();

GenericList<Struct> list3 = new GenericList<Struct>();

Here, GenericList<float> is a generic class. In each of these instances of GenericList<T>, every occurrence of T in the class is substituted at run time with the type argument. By substituting the T, we have created three different type-safe using the same class.


Ques. 13): In C#, how do you tell the difference between boxing and unboxing?


Both boxing and unboxing are used to convert types, however they have some differences:

Boxing: Boxing is the conversion of a value type data type to an object or any interface data type that this value type implements. When the CLR converts a value type to an Object Type, it wraps the value in a System.Object and stores it in the application domain's heap region.


Unboxing: Unboxing is a technique for determining the value type of an object or any implemented interface type. Unboxing, on the other hand, must be done explicitly via code.

 The concept of boxing and unboxing underlies the C# unified view of the type system in which a value of any type can be treated as an object.


Ques. 14): What is the difference between a struct and a class in C#?


Class and struct are both user-defined data types, but have some major differences:


  • The struct is a value type in C# and it inherits from System.Value Type.
  • Struct is usually used for smaller amounts of data.
  • Struct can’t be inherited from other types.
  • A structure can't be abstract.
  • No need to create an object with a new keyword.
  • Do not have permission to create any default constructor.


  • The class is a reference type in C# and it inherits from the System.Object Type.
  • Classes are usually used for large amounts of data.
  • Classes can be inherited from other classes.
  • A class can be an abstract type.
  • We can create a default constructor.


Ques. 15): What is the difference between the dispose and finalize methods in C#?


Both finalise and dispose are strategies for releasing unmanaged resources.


  • Finalize is used to liberate unmanaged resources in the application domain that are no longer in use, such as files and database connections.
  • These are the resources that an object has before it is destroyed. Garbage Collector calls it in the internal process, and no user code or service can call it manual.
  • Finalize belongs to System.Object class.
  • When your code contains unmanaged resources, use it to ensure that these resources are removed when garbage collection occurs.


  • Dispose can also be used to liberate unmanaged resources in the Application domain, such as files and database connections, at any time.
  • Manual user code directly calls dispose.
  • We must implement the disposal method via the IDisposable interface if we want to use it.
  • It's a part of the IDisposable interface.
  • When building a custom class that will be used by other users, remember to include this.


Ques. 16): In C#, what is the difference between late and early binding?


One of the key concepts of OOPS is polymorphism, which includes late binding and early binding.

For example, one function calculateBill() will calculate premium, basic, and semi-premium clients' bills differently depending on their plans. The calculations for all of the customer objects are done differently using the same polymorphism function.

The.NET framework conducts the binding when an object is allocated to an object variable in C#.

Early binding occurs when the binding function is performed at build time. It investigates and tests the static objects' methods and properties. The amount of run-time mistakes is significantly reduced with early binding, and it executes swiftly.

Late binding, on the other hand, occurs when the binding occurs at runtime. Late binding occurs when run-time objects are dynamic (determined by the data they contain). It's slower because it's looking through during the process.


Ques. 17): Is it possible to utilise "this" inside a static method?


Because the keyword 'this' returns a reference to the current instance of the class containing it, we can't use it in a static method. Static methods (or any other static element) are not associated with a specific instance. We can't use this keyword in the body of static Methods since they exist without creating an instance of the class and are called with the name of the class, not by instance. In the case of Extension Methods, however, we can use the function's parameters.

Let's take a look at the keyword "this."

The "this" keyword in C# is a particular form of reference variable that is implicitly defined as the first parameter of the type class in which it is specified within each function Object() { [native code] } and non-static function.


Ques. 18): What are delegates in C# and how do you utilise them?


A Delegate is an abstraction of one or more function pointers (as in C++; a detailed explanation is beyond the scope of this article). The concept of function pointers has been implemented in the form of delegates in.NET. You can use delegates to treat a function like data. Functions can be supplied as parameters, returned as a value, and saved in an array using delegates. The following are qualities of delegates:

  • Delegates are derived from the System.MulticastDelegate class.
  • They have a signature and a return type. A function that is added to delegates must be compatible with this signature.
  • Delegates can point to either static or instance methods.
  • Once a delegate object has been created, it may dynamically invoke the methods it points to at runtime.
  • Delegates can call methods synchronously and asynchronously.

There are a few useful fields in the delegate. The first has an object reference, whereas the second contains a method pointer. The instance method on the contained reference is called when you call the delegate. If the object reference is nil, however, the runtime interprets this to suggest that the method is static. Furthermore, calling a delegate is syntactically identical to calling a regular function. Delegates are thus ideal for implementing callbacks.


Ques. 19): In C#, describe accessibility modifiers. Why should you use access modifiers?


Access modifiers are keywords that specify a member's or type's declared accessibility.

Access modifiers are keywords that describe the accessibility of a type member or the type itself. A public class, for example, is open to the entire world, whereas an internal class is only open to the assembly.

Object-oriented programming relies heavily on access modifiers. To implement OOP encapsulation, access modifiers are utilised. You can use access modifiers to control who has and doesn't have access to particular functionalities.

In C# there are 6 different types of Access Modifiers:

public:    There are no restrictions on accessing public members.

Private:    Access is limited to within the class definition. This is the default access modifier type if none is formally specified

protected:    Access is limited to within the class definition and any class that inherits from the class

internal:    Access is limited exclusively to classes defined within the current project assembly

protected internal:    Access is limited to the current assembly and types derived from the containing class. All members in the current project and all members in derived class can access the variables.

private protected:    Access is limited to the containing class or types derived from the containing class within the current assembly.


Ques. 20): In C#, how do you use the using statement?


The using keyword in C# can be used in two ways. One is in the form of a mandate, while the other is in the form of a statement. Let me clarify!

using Directive:

In code-behind and class files, we usually utilise the using keyword to add namespaces. Then it makes all the classes, interfaces, and abstract classes on the current page, as well as their methods and properties, available.

Using Statement :

Another approach to utilise the using keyword in C# is as follows. It is critical to enhance garbage collection performance.

February 12, 2021

Top 20 C++ language Interview Questions & Answers


Ques. 1): What is ‘this’ pointer?

Answer: The ‘this’ pointer is passed as a hidden argument to all non-static member function calls and is available as a local variable within the body of all non-static functions. ‘this’ pointer is a constant pointer that holds the memory address of the current object. ‘this’ pointer is not available in static member functions as static member functions can be called without any object (with class name).


Ques. 2): What are VTABLE and VPTR?

Answer: vtable is a table of function pointers. It is maintained per class.

vptr is a pointer to vtable. It is maintained per object.

Compiler adds additional code at two places to maintain and use vtable and vptr.

1) Code in every constructor. This code sets vptr of the object being created. This code sets vptr to point to vtable of the class.

2) Code with polymorphic function call (e.g. bp->show()). Wherever a polymorphic call is made, compiler inserts code to first look for vptr using base class pointer or reference, for example, since pointed or referred object is of derived type, vptr of derived class is accessed). Once vptr is fetched, vtable of derived class can be accessed. Using vtable, address of derived derived class function show() is accessed and called.


Ques. 3): What do you mean by ‘void’ return type?

Answer: All functions should return a value as per the general syntax.

However, in case, if we don’t want a function to return any value, we use “void” to indicate that. This means that we use “void” to indicate that the function has no return value or it returns “void”.


void myfunc()


Cout<<”Hello,This is my function!!”;


int main()



return 0;



Ques. 4): What is an Inline function in C++?

Answer: Inline function is a function that is compiled by the compiler as the point of calling the function and the code is substituted at that point. This makes compiling faster. This function is defined by prefixing the function prototype with the keyword “inline”.

Such functions are advantageous only when the code of the inline function is small and simple. Although a function is defined as Inline, it is completely compiler dependent to evaluate it as inline or not.


Ques. 5): What is a Reference Variable in C++?

Answer: A reference variable is an alias name for the existing variable. This means that both the variable name and the reference variable point to the same memory location. Hence, whenever the variable is updated, the reference is updated too.


int a=10;

 int& b = a;

Here, b is the reference of a.


Ques. 6): When to use “const” reference arguments in a function?

Answer: Using “const” reference arguments in a function is beneficial in several ways:

   “const” protects from programming errors that could alter data.

   As a result of using “const”, the function is able to process both const and non-const actual arguments, which is not possible when “const” is not used.

   Using a const reference will allow the function to generate and use a temporary variable in an appropriate manner.


Ques. 7): What is the main difference between Class and Structure.


Structure: In C language, the structure is used to bundle different types of data types together. The variables inside a structure are called the members of the structure. These members are by default public and can be accessed by using the structure name followed by a dot operator and then the member name.

Class: Class is a successor of the Structure. C++ extends the structure definition to include the functions that operate on its members. By default, all the members inside the class are private.


Ques. 8): What is Namespace?

Answer: Namespace allows us to group a set of global classes, objects and/or functions under a specific name.

The general form to use namespaces is:

namespace identifier { namespace-body }

Where identifier is any valid identifier and the namespace-body is the set of classes, objects, and functions that are included within the namespace. Namespaces are especially useful in the case where there is a possibility for more than one object to have the same name, resulting in name clashes.


Ques. 9): What is Name Mangling?

Answer: C++ compiler encodes the parameter types with function/method into a unique name. This process is called name mangling. The inverse process is called as demangling.


A::b(int, long) const is mangled as ‘b__C3Ail’.

For a constructor, the method name is left out.

That is A:: A(int, long) const is mangled as ‘C3Ail’.


Ques. 10): What is a COPY CONSTRUCTOR and when is it called?

Answer: A copy constructor is a constructor that accepts an object of the same class as its parameter and copies its data members to the object on the left part of the assignment. It is useful when we need to construct a new object of the same class.


class A{

int x; int y;

public int color;

public A() : x(0) , y(0) {} //default (no argument) constructor

public A( const A& ) ;


A::A( const A & p )


this->x = p.x;

this->y = p.y;

this->color = p.color;




A Myobj;

Myobj.color = 345;

A Anotherobj = A( Myobj ); // now Anotherobj has color = 345



Ques. 11): What is the main difference between Declaration and Definition of a variable?

Answer: The declaration of a variable is merely specifying the data type of a variable and the variable name. As a result of the declaration, we tell the compiler to reserve the space for a variable in the memory according to the data type specified.


int Result;

char c;

int a,b,c;

All the above are valid declarations. Also, note that because of the declaration, the value of the variable is undetermined.

Whereas, a definition is an implementation/instantiation of the declared variable where we tie up appropriate value to the declared variable so that the linker will be able to link references to the appropriate entities.

From above Example,

Result = 10;

C = ‘A’;

These are valid definitions.


Ques. 12): What is Local and Global scope of a variable in C++?

Answer: The scope of a variable is defined as the extent of the program code within which the variable remains active i.e. it can be declared, defined or worked with.

There are two types of scope in C++:

1. Local Scope: A variable is said to have a local scope or is local when it is declared inside a code block. The variable remains active only inside the block and is not accessible outside the code block.

2. Global Scope: A variable has a global scope when it is accessible throughout the program. A global variable is declared on top of the program before all the function definitions.


#include <iostream.h>

Int globalResult=0; //global variable

int main()


Int localVar = 10; //local variable.



Ques. 13): What is the precedence when there are a Global variable and a Local variable in the program with the same name?

Answer: Whenever there is a local variable with the same name as that of a global variable, the compiler gives precedence to the local variable.


#include <iostream.h>

int globalVar = 2;

int main()


int globalVar = 5;



The output of the above code is 5. This is because, although both the variables have the same name, the compiler has given preference to the local scope.


Ques. 14): What is a Constant? Explain with an example.

Answer: A constant is an expression that has a fixed value. They can be divided into integer, decimal, floating-point, character or string constants depending on their data type.

Apart from the decimal, C++ also supports two more constants i.e. octal (to the base 8) and hexadecimal (to the base 16) constants.

Examples of Constants:

      75 //integer (decimal)

      0113 //octal

      0x4b //hexadecimal

      3.142 //floating point

      ‘c’ //character constant

      “Hello, World” //string constant


Ques. 15): What is the difference between equal to (==) and Assignment Operator (=)?

Answer: In C++, equal to (==) and assignment operator (=) are two completely different operators.

Equal to (==) is an equality relational operator that evaluates two expressions to see if they are equal and returns true if they are equal and false if they are not.

The assignment operator (=) is used to assign a value to a variable. Hence, we can have a complex assignment operation inside the equality relational operator for evaluation.


Ques. 16): what is the difference between Pre and Post Increment/Decrement Operations in C++?

Answer: C++ allows two operators i.e ++ (increment) and –(decrement), that allow you to add 1 to the existing value of a variable and subtract 1 from the variable respectively. These operators are in turn, called increment (++) and decrement (–).




The second statement, a++, will cause 1 to be added to the value of a. Thus a++ is equivalent to

a = a+1; or

a += 1;

A unique feature of these operators is that we can prefix or suffix these operators with the variable. Hence, if a is a variable and we prefix the increment operator it will be


This is called Pre-increment. Similarly, we have pre-decrement as well.

If we prefix the variable a with an increment operator, we will have,


This is the post-increment. Likewise, we have post-decrement too.

The difference between the meaning of pre and post depends upon how the expression is evaluated and the result is stored.

In the case of the pre-increment/decrement operator, the increment/decrement operation is carried out first and then the result passed to an lvalue. Whereas for post-increment/decrement operations, the lvalue is evaluated first and then increment/decrement is performed accordingly.


a = 5; b=6;

++a;       #a=6

b–;         #b=6

–a;         #a=5

b++;      #6


Ques. 17): What is Data Abstraction in C++?

Answer: Data Abstraction is a technique of providing only essential information of any application to the user and hiding its implementation, thus making the data more secure.

Example: Consider WhatsApp, we as users can only have a look at the elements useful for us and operate using the same but we never know what happens in the background.


Ques. 18): What is a destructor, and can there be more than one destructor in a class?

Answer: Destructors are used to de-allocate the memory that has been allocated for an object by the constructor. It has the same name as of the class name with a tilde symbol in front of the class name.

Syntax: class_name() { }

Also, there should be only one destructor in a class even if there are more than one constructors in a single class with no parameters and no return type.


Ques. 19): What is Pure Virtual Function?

Answer: A pure virtual function is a virtual function which does not contain any definition. The normal virtual function is preceded with a keyword virtual. Whereas the pure virtual function is preceded with the keyword virtual and ended with the value 0.

Example: virtual void add() = 0;


Ques. 20): Are exceptions and errors the same?

Answer: No. Errors occur because of any mistakes in the syntax of the program. i.e. errors occur during compile time. Whereas exceptions during run time of the program.

Example: If you forget to give semicolon at the end of an assignment statement, then it is an error. If you give 6 input values to an array which is declared only to store 5 elements, then that is an exception.