Advanced C# .Net Questions and Answers

Question – Define assembly.
Answer – 
An assembly is the primary unit of a .NET application. It includes an assembly manifest that describes the assembly.

Question – What is Constructor?
Answer – 
It is the first method that are called on instantiation of a type. It provides way to set default values for data before the object is available for use. Performs other necessary functions before the object is available for use.

Question – What is Destructor? 
Answer – It is called just before an object is destroyed. It can be used to run clean-up code. You can’t control when a destructor is called since object clean up by common language runtime.

Question – Define Abstract class in C#.NET.
Answer – Abstract class cannot be instantiated.
Same concept in C++ known as pure virtual method.
A class that must be inherited and have the methods over-ridden.
A class without any implementation.

Question – Explain serialization? 
Answer – 
Serialization is a process of converting an object into a stream of bytes. .Net has 2 serializers namely XMLSerializer and SOAP/BINARY Serializer. Serialization is maily used in the concept of .Net Remoting.

Question – C#.Net support multiple inheritance, comment.
Answer – No, but we can use interface instead.

Question – Can private virtual methods be overridden in C#.NET?
Answer – No, moreover, you cannot access private methods in inherited classes,
They have to be protected in the base class to allow any sort of access.

Question – Is is possible to force garbage collector to run?
Answer Yes, we can force garbage collector to run using System.GC.Collect().

Question – How do you inherit derived class from a base class in C#.NET?
Answer – 
By using colon and then the name of the base class.

Question – Name the Top .NET class that everything is derived from.
Answer – System.Object.

Question – Define protected class-level variable in C#.NET.
Answer – It can be inherited by the classes in the same namespace.

Question – Is it possible to inherit private class-level variables?
Answer – No.

Question – Is it possible to inherit multiple interfaces in C#.NET?
Answer – Yes.

Question – Define Protected internal.
Answer – It is available to derived classes and classes within the same Assembly.

Question – How to prevent your class from being inherited?
Answer – You can use keyword ‘sealed’ in the class definition to prevent class from being inherited.

Question – List down difference between overriding and overloading.
Answer – 
When overriding, you change the method behavior for a derived class.
Overloading simply involves having a method with the same name within the class.

Question – What does the keyword virtual mean in the method definition?
Answer – The method can be over-ridden.

Question – How to allow class to be inherited, but prevent the method from being over-ridden?
Answer – You can do so by declaring the class public and making the method sealed.

Question – When do we declare a class as abstract in C#.NET?
Answer – When at least one of the methods in the class is abstract.

Question – Define Interface class in C#.NET.
Answer – It is an abstract class with public abstract methods with no implimentation

Question – Difference between an interface and abstract class
Answer – In the interface all methods must be abstract;
In the abstract class some methods can be concrete.
In the interface no accessibility modifiers are allowed, which is possible in abstract classes.

Question – How can you overload a method?
Answer – Different parameter data types, different number of parameters, different order of parameters.

Question – Difference between System.String and System.StringBuilder classes.
Answer – System.String is immutable;
System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

Question – Define Delegate.
Answer – A delegate object encapsulates a reference to a method.
In C++ they were referred to as function pointers.

Question – How is DLL Hell problem solved in .NET?
Answer – Assembly versioning helps to resolve not only the library it needs to run , but also the version of the assembly.

Question – Ways to deploy an assembly.
Answer – MSI installer, a CAB archive, and XCOPY command

Question – Define Satellite Assembly.
Answer – When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

Question – Namespaces to create a localized application.
Answer – System Globalization, System Resources.

Question – List out difference between the Debug class and Trace class.
Answer – Use debug class for debug builds, use Trace class for both debug and release builds.

Question – What are three test cases you should go through in unit testing?
Answer – Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).

Start Your Search Today

Find opportunities in the following fields: Technology, Customer Service, Human Resource, & Finance and Accounting