Showing posts with label microsoft. Show all posts
Showing posts with label microsoft. 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?

Answer:

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?

Answer:

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?

Answer:

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

Answer:

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?

Answer:

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?

Answer:

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()?

Answer:

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?

Answer:

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#?

Answer:

 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?

Answer:

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?

Answer:

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#?

Answer:

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?

Answer:

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#?

Answer:

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

Struct

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

Class

  • 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#?

Answer:

Both finalise and dispose are strategies for releasing unmanaged resources.

 Finalize: 

  • 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: 

  • 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?

Answer:

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?

Answer:

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?

Answer:

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?

Answer:

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?

Answer:

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.