Skip to main content

Top 15 C# Interview Question

 



C# is a Microsoft-developed, general-purpose, object-oriented programming language.
It is one of the most flexible programming languages with a powerful runtime, access to a huge amount of library and platform functionality, and a strong set of abstractions.

Using C#, you are prone to create web applications or gaming apps. C# has some fantastic features like automatic garbage collection, interfaces, etc. which help build better applications.

C# is such a widely-used programming language, a plethora of big and small organizations base their products using it. So, prepare yourself with basic and advanced level C# questions to ace the interviews. 


Top 15 C# Interview Questions and Answers.

   
          Now, let us take a look at the top C# interview questions that you might face.
   

1.Explain the difference between .NET and C#?

    C# is a programming language and .NET is a framework .NET has Common Language  Runtime (CLR), which is a virtual component of .NET framework.

     C# is a part of .NET and has the following features −

  • Boolean Conditions
  • Automatic Garbage Collection
  • Standard Library
  • Assembly Versioning
  • Properties and Events
  • Delegates and Events Management
  • Easy-to-use Generics
  • Indexers
  • Conditional Compilation
  • Simple Multithreading
  • LINQ and Lambda Expressions
  • Integration with Windows

2.What is  IL (Intermediate Language) code?

   Intermediate language (IL) is an object-oriented programming language designed to be used by compilers for the .NET Framework before static or dynamic compilation to machine code.

IL(Intermediate language) code is a partially compiled code .JIT(Just in Time compiler compiled intermediate language code to native code (machine code).



3.What is CLR(Common Language Runtime)?

.NET CLR is a runtime environment that manages and executes the code written in any .NET programming language. CLR is the virtual machine component of the .NET framework.

The main components of  CLR are :

  • Common type system
  • Common language speciation
  • Garbage Collector
  • Just in Time Compiler
  • Metadata and Assemblies




4.What is Managed and Unmanaged code?

Any language that is written in the .NET framework is managed code. Managed code use CLR.

Benefits: Provides various services like a garbage collector, exception handling, etc. 

The code developed outside the .NET framework is known as unmanaged code. Applications that do not run under the control of the CLR are said to be unmanaged. 

They don’t provide services of the high-level languages and therefore, run without them. Such an example is C++. 



5.Explain the importance of Garbage collector?

Garbage collection is the process of freeing up memory that is captured by unwanted objects. When you create a class object, automatically some memory space is allocated to the object in the heap memory. Now, after you perform all the actions on the object, the memory space occupied by the object becomes waste. It is necessary to free up memory. Garbage collection happens in three cases:

  • 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


6.Explain Boxing and Unboxing?

 The two functions are used for typecasting the data types:

Boxing: Boxing converts value type (int, char, etc.) to reference type (object) which is an implicit conversion process using object value. 

Unboxing: Unboxing converts reference type (object) to value type (int, char, etc.) using an explicit conversion process



7.Difference Between array and arraylist?

An array is a collection of similar variables clubbed together under one common name. While ArrayList is a collection of objects that can be indexed individually. With ArrayList you can access a number of features like dynamic memory allocation, adding, searching, and sorting items in the ArrayList.
 

8.What are Generic collections?

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


9.How do we handle exception in C#?

Exceptions provide a way to transfer control from one part of a program to another. C# exception handling is built upon four keywords: trycatchfinally, and throw.
try − A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks.
catch − A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.
finally − The finally block is used to execute a given set of statements, whether an exception is thrown or not thrown. For example, if you open a file, it must be closed whether an exception is raised or not.
throw − A program throws an exception when a problem shows up. This is done using a throw keyword.

10.What are extension methods in C#?

Extension methods help to add new methods to the existing ones. The methods that are added are static. At times, when you want to add methods to an existing class but don’t perceive the right to modify that class or don’t hold the rights, you can create a new static class containing the new methods. Once the extended methods are declared, bind this class with the existing one and see the methods will be added to the existing one.





11.What are the differences between ref and out keywords?

C# ref keywords pass arguments by reference and not value. To use the ‘ref’ keyword, you need to explicitly mention ‘ref’. 
C# out keywords pass arguments within methods and functions. 
‘out’ keyword is used to pass arguments in a method as a reference to return multiple values. Although it is the same as the ref keyword, the ref keyword needs to be initialized before it is passed. Here, The out and ref keywords are useful when we want to return a value in the same variables that are passed as an argument. 
12.What are Properties in C#?
Properties in C# are public members of a class where they provide the ability to access private members of a class. The basic principle of encapsulation lets you hide some sensitive properties from the users by making the variables private. The private members are not accessible otherwise in a class. Therefore, by using properties in C# you can easily access the private members and set their values. 


The values can be easily assigned using get and set methods, also known as accessors. While the get method extracts the value, the set method assigns the value to the variables. 




13.What are events?

Events are user actions such as key press, clicks, mouse movements, etc., or some occurrence such as system generated notifications. Applications need to respond to events when they occur. For example, interrupts. Events are used for inter-process communication.
The events are declared and raised in a class and associated with the event handlers using delegates within the same class or some other class. The class containing the event is used to publish the event. This is called the publisher class. Some other class that accepts this event is called the subscriber class. Events use the publisher-subscriber model.
publisher is an object that contains the definition of the event and the delegate. The event-delegate association is also defined in this object. A publisher class object invokes the event and it is notified to other objects.
subscriber is an object that accepts the event and provides an event handler. The delegate in the publisher class invokes the method (event handler) of the subscriber class.


14.What are difference between abstract class and interface ?

  • Abstract classes are classes that cannot be instantiated i.e. that cannot create an object. The interface is like an abstract class because all the methods inside the interface are abstract methods.
  • Surprisingly, abstract classes can have both abstract and non-abstract methods but all the methods of an interface are abstract methods.
  • Since abstract classes can have both abstract and non-abstract methods, we need to use the Abstract keyword to declare abstract methods. But in the interface, there is no such need.

15. What are Indexers in C#?

Indexers are called smart arrays that allow access to a member variable. Indexers allow member variables using the features of an array. They are created using the Indexer keyword. Indexers are not static members. 
For ex. Here the indexer is defined the same way.
























Comments

Popular posts from this blog

Meteorological Data Analysis

Is there any change due in weather to global warming in of Finland by using Data analytics                                       Effect of  global warming  “Has the Apparent temperature and humidity compared monthly across 10 years of the data indicate an increase due to Global warming” To find whether the average Apparent temperature for the month of a month say April starting from 2006 to 2016 and the average humidity for the same period have increased or not. step-1  Importing of libraries and Dataset.   import libraries step-2   over Look at the dataset. step-3 Cleaning the Dataset step-4 Plotting a graph of  the following Dataset >  Firstly  plot the  graph whole dataset for all months  Graph for all month >  Now    plot graph for a specific month(April) .   Graph for  month of April Conclusion: As we can analyze there isn’t any change in humidity in past 10 years( 2006–2016) for the month of April.  where as , temperature increases sharply in 2009 and drops in 2015 for rest

Mechanical and durability Behavior of fiber reinforced concrete incorporating deferent types of natural, pp and steel fibers

  1. Introduction As an important building material, concrete has been widely used in civil engineering applications such as bridges and roads engineering, and the related experimental study of the mechanical properties of concrete was also fruitful . With the vigorous development of engineering construction, high-performance concretes such as fiber-reinforced concrete was applied gradually in important engineering structures . Among these high-performance concretes, for the advantages of low cost, easy fabrication, and performance improvements, obviously, steel fiber-reinforced concrete was used widely in the current engineering field . However, the study showed that uneven incorporation of steel fiber would affect the fluidity and uniformity of concrete mixing and even result in fiber bonding, which eventually affects the reinforcement effect of mechanical properties. Up to now, most research paid attention on the improvement effect of different types of fiber or optimum fiber conten

catalysis by organometallic compound

1)  what is alkene hydrogenation  ? An alkene  addition reaction is a process  called  hydrogenation . In a hydrogenation reaction  two hydrogen atom  are added  across   the double bond   of an  alkene  resulting  in a saturated  alkene . The heat released is called  heat of hydrogenation .  2) what is  wilkinson's catalyst ?   First effect homogenious  catalyst   is a  square  planner  16 electron  d8 complex  chlorotris (triphenyl phosphine ) rhodium(1) called  wilkinson's catalyst .  3) what do you understand by Tolman catalytic loops ?   A  reaction  involving  a true catalyst  can always be represented  by   a closed loop is called  Tolman catalytic loops.  4)Explain the term hydroformylation  ? Hydroformylation   also called a oxoprocess  or oxo synthesis  It is an industrial process  to prepare  aldehyde from alkanes .  In this process  there is a net addition  of formyl group(-CHO) and  a hydrogen atom to a   C = C  double bond . This process is considered as very impo