C#.Net Interview Questions and answers
Question.1. What is C#?
Answer: C# (pronounced C-Sharp) is a new programming language introduced with the Microsoft .NET framework and is no doubt the language of choice in .NET environment. It was first created in the late 1990’s as part of Microsoft’s whole .NET strategy. It is a whole new language free of backward compatibility curse and a whole bunch of new, exciting and promising features. It is an Object Oriented Programming language, which at its core, has similarities with Java, C++ and VB.
Question.2 What are Jagged Arrays in C#?
Answer: A special type of array is introduced in C#. A Jagged Array is an array of an array in which the length of each array index can differ. Example: A Jagged Array can be used is to create a table in which the lengths of the rows are not same. This Array is declared using square brackets ( [ ] ) to indicate each dimension.
Question.3 How do you prevent the class from being inheritance?
Answer: Simply include the keyword ‘Sealed’ in front of the class keyword.
Question.4 What’s the advantage of using System.Text.StringBuilder over System String?
Answer: String Builder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
Question.5. Explain the use of abstraction in C#.NET?
Answer: Abstraction is used to create a common set of methods that might have different specific implementations by subclasses. Abstract class cannot be instantiated and consists of abstract methods without any implementations. Classes inheriting from abstract class must implement all the methods in abstract class.
Question.6 What is the Difference between instance data and class data?
Answer: Class data in terms of static class is the data that particular class holds in its structure. Instances can refer to different objects of the same class that hold different values using the same class structure in memory heap.
Question.7 Explain the significance of static method?
Answer: Static methods are used when we want only one copy of that method to perform action and remain active at a single point in time.
Question.8 Explain the uses of boxing and unboxing?
Answer: Boxing and Unboxing are used to convert value types into reference types and vice versa. Developers often need to make some methods generic and hence create methods that accept objects rather than specific value types. The advantage of reference types is that they don’t create a copy of the object in memory, instead pass the reference of the data in the memory. This uses memory much more efficiently, especially, if the object to be passed is very heavy.
Question.9 Explain the Debug class methods?
a. Assert:This method checks for a condition. It displays a user message if the condition is false.
b. Write:used to write information which will be used by Trace Listeners.
c. WriteIf:Write information for Trace Listeners only if the condition is true.
d. WriteLine: same as write but, every time writes in a new line.
e. WriteLineIf: same as Write If but every time writes in a new line.
Question.10 What is Anchoring a control and Docking a control?
Answer: Anchoring: used to resize controls dynamically with the form.
Docking: to adhere to the edges of its container.
Question.11 What is Form level validation and Field level Validation?
Question.12 What is Code-Access security?
Answer: Code access security is a mechanism that helps limit the access to the code by protecting the resources. It defines permissions which tell about the rights to access various. It also imposes restrictions on code at run time.
Question.13 What is the difference between DataGrid control in Windows Forms and Web Forms?
Answer: Windows Forms controls have more functionality than Web Forms. Also, DataGrid in Web Forms has to be bound to the form before it displays any data.
Question.14 What is the difference between Finalize() and Dispose()?
Answer: Dispose() is called by as an indication for an object to release any unmanaged resources it has held.Finalize() is used for the same purpose as dispose however finalize doesn’t assure the garbage collection of an object.Dispose() operates determinilistically due to which it is generally preferred.
Question.15 How does the XmlSerializer work? What ACL permissions does a process using it require?
Answer: The XmlSerializer constructor generates a pair of classes derived from XmlSerializationReader and XmlSerializationWriter by analysis of the classes using reflection. Temporary C# files are created and compiled into a temporary assembly and then loaded into a process.The XmlSerializer caches the temporary assemblies on a per-type basis as the code generated like this is expensive. This cached assembly is used after a class is created.Therefore the XmlSerialize requires full permissions on the temporary directory which is a user profile temp directory for windows applications.
Question.16 What are circular references?how garbage collection deals with circular references?
Answer: A circular reference is a run-around wherein the 2 or more resources are interdependent on each other rendering the entire chain of references to be unusable.There are quite a few ways of handling the problem of detecting and collecting cyclic references.
1. A system may explicitly forbid reference cycles.
2. Systems at times ignore cycles when they have short lives and a small amount of cyclic garbage. In this case a methodology of avoiding cyclic data structures is applied at the expense of efficiency.
Question.17 What is the difference between Interface-oriented, Object-oriented and Aspect-oriented programming?
Answer: Interface oriented approach compels to develop the software based on the contract. Object oriented approach emphasizes on its aspects like, Abstraction, Encapsulation, Inheritance, Polymorphism. Cross cutting concerns cannot be implemented in object oriented programming. That’s not the case with aspect-oriented. However, there is a risk of system failure in this situation.
Question.18. What is the accessibility modifier “protected internal” in C#.?
Answer: The Protected Internal access modifier can be accessed by:
Members of the Assembly
The inheriting class
The class itself,
Its access is limited to the types derived from the defining class in the current assembly or the assembly itself.
Question.19 What is the difference between Debug.Write and Trace.Write? When should each be used?
Answer: Debug.Write: Debug Mode, Release Mode (used while debugging a project).
Trace.write: Release Mode (used in Released verion of Applications).
Get A Live Demo : C# NET Training