28
DecChristmas Special : Upto 40% OFF! + 2 free courses - SCHEDULE CALL
C# is a computer language that runs on the .NET Framework. It is type-safe object-oriented which is not only simple, but also an elegant language that enables developers to build a lot of secure and robust applications like Windows client applications, XML Web services, distributed components, client-server applications, database applications, and a lot more. Many advanced options like advanced code editor, convenient user interface designers, integrated debugger, and many other tools are provided by Visual C# to make it easier for the developers to develop applications based on the C# language and the .NET Framework.
C# alternately referred as C sharp was developed by Microsoft. The syntax that uses curly-brace of C# is instantly recognizable as it is a language based on C, C++ or Java. Developers who have the knowledge of any of these languages are able to work in C# within a very short time. The nullable value types, enumerations, delegates, lambda expressions and direct memory access are the powerful features provided by C#, which simplifies C++ and are add-ons that are not available in Java.
We have compiled a list of top C# interview questions which are classified into 5 sections, namely:
C# supports generic methods and types. C# provides increased type safety and performance, and using iterators it enables implementation of collection classes that define custom iteration behaviours. With the help of Language-Integrated Query (LINQ) expressions, C# makes a strongly-typed query a first-class language construct.
For Windows, C# is currently the most used languages in the development of third-party apps. It also is a very popular language for mobile devices, including the Windows Phone. The job opportunities have spurred with the growth of Windows, and with the increase in vacancies the completion increases. Down we have categorized some important questions for the beginners and experienced candidates, which will help you crack the interview.
Q1). Explain the fundamental concepts of OOP?
There are four fundamental concepts of Object Oriented Programming, they are:
Q2). What are the benefits of using C#?
Here are a few advantages of using C#-
A typical C# program consists of a namespace declaration, methods, attributes, a class, the main method, statements, expressions, and comments.
Q4). What is an Interface in C#?
An Interface is a class with no execution. The main thing that it contains is the declaration of techniques, properties, and events.
Q5). What are the various types of classes in C#?
There are different types of class in C#, they are:
[code lang="plain"]using System; namespace AllTheBestApplication { class AllTheBest { static void Main(string[] args) { Console.WriteLine("Hello World"); Console.ReadKey(); } } } [/code]
Read: Top 85 .Net Interview Questions and Answer
In C# most of the built-in operators are available and can be overloaded or redefined using the operator keyword. The example below explains the syntax used to implement the addition operator(+) for a user-defined class. [code lang="plain"]public static Rectangle operator+ (Rectangle b, Rectangle c) { Rectangle rectangle = new Rectangle(); rectangle.length = b.length + c.length; rectangle.breadth = b.breadth + c.breadth; rectangle.height = b.height + c.height; return rectangle; } [/code]
Dynamic type variables handle type checking at the runtime. Object type variables handle type checking during compile time.
Encapsulation is a classic object-oriented design principle. Encapsulation reduces coupling between objects and increases maintainable code. It involves enclosing objects within a logical pack by limiting access to implementation details. In C# encapsulation is achieved through the access specifiers public, private, protected, internal, and protected internal.
[code lang="plain"]delegate void Iterator(); static void Main() { List iterators = new List(); For (int i = 0; i < 15; i++) { iterators.Add(delegate { Console.WriteLine(i); }); } Foreach (var iterator in iterators) { iterator(); } } [/code] the number 15 is printed fifteen times.
Explanation– The program tests the developer on their knowledge working with loops and delegates. As the delegate is added within the for loop, and because the delegate is the only reference for the variable instead of the value itself, the loop sets the value of the variable I to 15 before it is called within each delegate.
Generics allow a developer to define a class or method that can work with virtually any data type. It works by delaying specification of the programming element data types until they are needed. The main features of generics are:
Dispose method uses an interface as “IDisposable" interface and it will free up all managed and unmanaged codes like database connection, files etc. Dispose of the method which is called explicitly. Finalize, unlike dispose method finalize is called internally. It is called by the garbage collector and cannot be called directly from the code.
Array | ArrayList |
The same data type of values or elements are stored in the array | Values of different data types are stored in ArrayList. |
Arrays will use the fixed length | ArrayList does not use fixed length |
Q15). What is an Escape Sequence?
An Escape grouping is signified by an oblique punctuation line (\). The oblique punctuation line shows that the character that tails it ought to be deciphered actually or it is a unique character. An escape sequence is considered a solitary character.
Q16). What is Reflection in C#?
Reflection is the capacity of a code to get to the metadata of the assembly amid runtime. A program reflects upon itself and utilizes the metadata to educate the user or adjust its conduct. Metadata alludes to data about objects, techniques, methods.
You can define “targetFramework” in Web.config file to specify the framework version. It is introduced in Asp.net 4.0. [code lang="plain"]<?xml version="1.0"?> <configuration> <system.web> <compilation targetframework="4.0" /> </system.web> </configuration> [/code]
Static Class | Singleton instance |
A static class cannot implement an interface | A singleton instance can implement an interface |
Cloning of objects is not possible | Cloning of objects is possible |
Stores in stack | Stores in heap |
Generally initialized when it is first loaded | Can be initialized lazily or asynchronously |
The Singleton pattern is considered an anti-pattern because they are not easy to handle with unit test and their instantiation cannot be controlled, Memory allocated to a Singleton cannot be freed. In the multithreaded environment, access to the singleton object should be guarded in the multithreaded environment, and it is hard to test as it promotes tight coupling between classes.
Q19). What are C# I/O Classes? What are the commonly used I/O Classes?
C# has System.IO namespace, comprising of classes that are utilized to perform different tasks on records like making, erasing, opening, closing and so on.
Read: C# Developer Job Description You Can’t Miss Learning About
Q20). Differentiate between Managed and Unmanaged code?
Managed Code | Unmanaged Code |
Managed code is a code which is executed by CLR (Common Language Runtime) i.e all application code is dependent on.Net Platform. It is considered as overseen in view of them. The net structure which internally utilizes the junk collector to clear up the unused memory. | Unmanaged code is any code that is executed by application runtime of some other structure separated from.Net. The application runtime will deal with memory, security and other execution activities. |
Q21). Explain the process of Code compilation in C#.
There are four steps in the procedure involved in code compilation which include:
C# Interview Questions For Fresher
Q22). Elucidate the difference between Virtual method and Abstract method?
Virtual Method | Abstract Method |
A Virtual method dependably has a default execution. Nonetheless, it very well may be abrogated in the determined class, however not obligatory. It tends to be superseded utilizing override keyword. | An Abstract method does not have a usage. It lives in the abstract class. It is obligatory that the determined class actualizes the dynamic strategy. An override keyword isn't essential here however it tends to be utilized. |
Q23). Explain what is Namespaces in C#.
They are utilized to compose substantial code ventures. "System" is the most broadly utilized namespace in C#. We can make our very own namespace and utilize one namespace in another, which are called Nested Namespaces. They are indicated by the keyword "namespace".
Q24). How is Exception Handling executed in C#?
Exception handling is done using four keywords in C#:
Q25). What is a Deadlock?
A Deadlock is where a procedure can't finish its execution since at least two procedures are waiting for each other to wrap up. This generally happens in multi-threading.
Q26). What is Serialization?
Serialization is a procedure of changing over a code to its twofold configuration. When it is changed over to bytes, it tends to be effortlessly put away and kept in touch with a plate or any such capacity gadgets. Serializations are chiefly helpful when we would prefer not to lose the first type of the code and it tends to be recovered whenever you want at a later stage.
In order to ensure a variable is valid before using it, nullable types help by creating a value type variable that can be marked as valid or invalid. Regular value types are called non-nullable types.
Extension methods enable adding new capabilities to an existing type. No modifications are needed to the existing type, just bringing the extension method into the scope and calling it like a regular instance method will serve the purpose. Extension methods have to be declared in a non-generic, non-nested static class.
Read: A Complete C Sharp Programming Beginners Tutorial
Q29). How to implement the Singleton design pattern in C#?
Implementing Singleton in C# can be done in numerous ways:
Throw | throw ex |
throw re-throws the exception that was caught | throw ex-throws the same exception. |
Preserves the stack trace | Resets the stack trace to that method |
Unless the requirement is to reset the stack trace (i.e. to shield public callers from the internal workings of the library), it is better to use the throw as it facilitates viewing the exception origin.
Q31). What is the use of the volatile keyword?
The volatile keyword redirects to a field and indicates it could be modified by multiple threads that are executed at the same time. Fields declared volatile are not optimized from compilers. It automatically assumes access by a single thread and makes sure the presence of most up-to-date value of fields at all times. The volatile modifier is usually used without using the lock statement to serialize access for a field that is accessed by multiple threads.
The volatile keyword can be applied to fields of the following types:
An async is a method that returns to the calling method before completing its work completely. It then completes its work while the calling method continues its execution.
Characteristics of an async method:
The object pool implementation increases the size of the pool to the maximum. Instead of throwing an exception, when the maximum is reached, it makes the client wait until an object is returned to the pool and then gives the newly returned object to the waiting client. The connection pool implementation does not require, a maximum size parameter – it will keep creating new connections as and when required in order to meet demand (eventually it will hit some system limit resulting in the failure in some way that isn’t specified.
Q34). Can you serialize hashtables and Why?
Serializing is not possible hashtables, because any object that implements the IDictionary interface, serialization is not allowed by .NET Framework.
Q35). What is?PDB file?
Program Data Base PDB is a repository (persistent storage as databases) to maintain the information required to run the program in debug mode. PDB contains a lot of relevant information while debugging the code.
A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.
Cyber Security
QA
Salesforce
Business Analyst
MS SQL Server
Data Science
DevOps
Hadoop
Python
Artificial Intelligence
Machine Learning
Tableau
Search Posts
Related Posts
Top 85 .Net Interview Questions and Answer 779.2k
What is Microsoft .Net Framework? Complete Architecture Tutorial Guide 130.1k
What Are The Roles & Responsibility Of A .Net Developer 946.3k
Microsoft .Net Software Developer Salary in USA 710.4k
Top 30 Advanced Microsoft Power BI Interview Questions & Answers 485.5k
Receive Latest Materials and Offers on Dotnet Course
Interviews