C# Interview Questions and Answers for 5 years Experienced
Q1. What is C-Sharp (C#)?
Ans: C# is a kind-secure, controlled and object orientated language, which is compiled with the aid of .Net framework for producing intermediate language (IL).
Q2. Explain the types of feedback in C#?
Ans: Below are the kinds of remarks in C#:
Single Line Comment Eg : //
Multiline Comments Eg: /* */
XML Comments Eg : ///
Q3. So what makes your code honestly item-oriented?
Ans: In order to apprehend this, we need to first analyze what blessings we are able to derive from OO. In order to do that, we have to genuinely understand its basis. So for the reason that C# is at its middle object-oriented.
Q4. What is Cohesion?
Ans: In OOPS we broaden our code in modules. Each module has certain obligations. Cohesion suggests how plenty a module obligations are strongly associated.
Higher concord is constantly desired. Higher cohesion blessings are:
Improves preservation of modules.
Q5. Why are strings in C# immutable?
Ans: Immutable way string values can not be changed when they have been created. Any modification to a string value results in a completely new string example, consequently an inefficient use of reminiscence and extraneous rubbish collection. The mutable System.Text.StringBuilder magnificence should be used while string values will exchange.
Q6. List out the differences between Array and Array List in C#?
Ans: Array shops the values or factors of identical statistics kind however array list shops values of various records sorts.
Arrays will use the constant length however array listing does not makes use of constant period like array.
Q7. What are the essential principles of OO programming?
Ans: As a developer, you is probably tempted to reply that it comprises things like Encapsulation, Polymorphism, Abstraction, and Inheritance. Although this is true, it doesn’t virtually explain the fundamental center of what OO is and what its benefits are.
Principles are important but they're now not the maximum vital issue of what OO without a doubt is. What is clearly critical is to recognize in what grounds OO is constructed upon, or in other words, what are the foundations of OO programming.
The maximum fundamental middle standards on which OO has been built upon in C# are this pointer and Dynamic Dispatch.
Obviously, there are ideas like Encapsulation, Polymorphism, Abstraction, and Inheritance, but those are the result and no longer the generating force behind the OO paradigm in C#.
Q8. What is coupling?
Ans: OOPS Modules are dependent on each different. Coupling refers to level of dependency between two software modules.
Two modules are extraordinarily dependent on every other if you have changed in a single module and for supporting that exchange on every occasion you have to exchange in dependent module.
Loose Coupling is always desired.
Inversion of Control and dependency injections are some techniques for buying unfastened coupling in modules.
Q9. What is the execution access factor for a C# console software?
Ans: The Main method.
Q10. Why to use “the use of” in C#?
Ans: “Using” assertion calls – “dispose” technique internally, whenever any exception occurred in any approach call and in “Using” declaration items are read simplest and cannot be reassignable or modifiable.
Q11. What is the this Pointer?
Ans: The this pointer is silently passed with a name to an instance-degree characteristic, which then operates on an object (instance of a category).
Basically, this center mechanism makes it viable to convey operations near facts. It additionally gets rid of the need to have worldwide functions and it gives information structures the intrinsic potential to perform operations on its data.
Q12. What is Abstraction?
Ans: Abstraction is a method of taking some thing unique and making it less precise.
In OOPS we attain the abstraction by means of keeping apart the implementation from interface. We take a carried out elegance and took best the ones method signatures and houses which are required by means of the elegance customer. We placed these technique signatures and properties into interface or abstract class.
Q13. How do you provoke a string without escaping each backslash?
Ans: You placed an @ check in front of the double-quoted string.
String ex = @"This has a carriage returnrn"
Q14. Explain namespaces in C#?
Ans: Namespaces are packing containers for the instructions. We will use namespaces for grouping the related training in C#. “Using” key-word can be used for the usage of the namespace in different namespace.
Q15. What is the OO essential concept using C# that lets in a statistics shape to carry out operations on its own facts?
Ans: What might your solution be? Pretty obvious. The humble this pointer.
Notice that regardless of this being a mind-bending concept, we are able to already begin to admire the larger image for which C# was designed.
The this pointer is basically a manner for a statistics shape (object) as a way to get admission to strategies that permit itself to carry out operations on its own data. It is a manner to manipulate country within a data structure.
Now let’s speak a piece approximately the alternative core idea that takes this to the following level.
Q16. What is Encapsulation?
Ans: In non item orientated languages, data and behaviors are not tied together. That method any feature in the software can modify the statistics.
In Encapsulation, we bind the facts and behaviors in one object. Only described behaviors in a category can alter the data. We disguise the state of an item by means of the use of residences and methods. Clients of the item handiest see those behaviors and by way of only those behaviors customers can modify the data.
We also defend the records by using get right of entry to specifiers. We positioned the private / protected keywords earlier than data to guard it from the outside world.
Q17. What is the distinction between a struct and a category?
Ans: Structs cannot be inherited. Structs are exceeded through value and no longer by using reference. Structs are saved on the stack not the heap. The end result is better performance with Structs.
Q18. Explain “static” key-word in C#?
Ans: “Static” key-word can be used for asserting a static member. If the class is made static then all the contributors of the elegance also are made static. If the variable is made static then it's going to have a single example and the fee change is up to date in this example.
Q19. What is a singleton?
Ans: A singleton is a design sample used while most effective one instance of an object is created and shared; that is, it simplest lets in one instance of itself to be created. Any try to create every other instance honestly returns a connection with the primary one. Singleton training are created by way of defining all class constructors as non-public. In addition, a private static member is created because the identical kind of the elegance, together with a public static member that returns an instance of the elegance. Here is a basic example:
public class SingletonExample personal static SingletonExample _Instance; private SingletonExample () public static SingletonExample Get Instance() if (_Instance == null) _Instance = new SingletonExample (); return _Instance;
Q20. Why to apply “in the end” block in C#?
Ans: “Finally” block can be completed no matter exception. So even as executing the code in strive block while exception is passed off, manipulate is again to catch block and at final “eventually” block might be carried out. So ultimate connection to database / liberating the record handlers can be kept in “sooner or later” block.
Q21. What is boxing?
Ans: Boxing is the manner of explicitly changing a value kind right into a corresponding reference kind. Basically, this involves growing a brand new item on the heap and setting the cost there. Reversing the technique is just as smooth with unboxing, which converts the price in an item reference on the heap into a corresponding fee kind on the stack. The unboxing technique starts offevolved by verifying that the recipient price kind is equal to the boxed type. If the operation is authorized, the fee is copied to the stack
Q22. Can we've got only “attempt” block with out “seize” block in C#?
Ans: Yes we are able to have simplest attempt block with out capture block.
Q23. How to move to a State-related Codebase?
Ans: So now that we’ve explored these ideas, allow’s circulate to a nation-related code base. So you might be asking yourself at this moment.
Q24. What is the difference among “out” and “ref” parameters in C#?
Ans: “out” parameter can be handed to a technique and it need now not be initialized wherein as “ref” parameter needs to be initialized before it's miles used.
Q25. How are strategies overloaded?
Ans: Methods are overloaded thru different signatures (range of parameters and brands). Thus, you can overload a method by way of having distinct facts kinds, one of a kind variety of parameters, or a exceptional order of parameters.
Q26. Explain Jagged Arrays in C#?
Ans: If the elements of an array is an array then it’s called as jagged array. The elements may be of various sizes and dimensions.
Q27. How do you prevent a class from being inherited?
Ans: The sealed key-word prohibits a class from being inherited.
Q28. What you suggest via internal exception in C#?
Ans: Inner exception is a property of exception magnificence which will come up with a quick insight of the exception i.E, discern exception and baby exception information.
Q29. What is the GAC, and where is it located?
Ans: The GAC is the Global Assembly Cache. Shared assemblies live inside the GAC; this permits programs to proportion assemblies instead of having the assembly dispensed with each software. Versioning permits more than one meeting versions to exist inside the GAC—packages can specify version numbers in the config report. The gacutil command line tool is used to manipulate the GAC.
Q30. Explain round reference in C#?
Ans: This is a scenario in which in, a couple of resources are depending on each different and this reasons a lock condition and this makes the useful resource to be unused