C#.NET Interview Question & Answer

1.What is the difference between Finalize() and Dispose()?

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 determinalistically due to which it is generally preferred.

2. How does the XmlSerializer work? What ACL permissions does a process using it require?

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.

3. What are circular references? Explain how garbage collection deals with circular references.

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.
  3. Another solution is to periodically use a tracing garbage collector cycles.
Other types of methods to deal with cyclic references are:
  • Weighted reference counting
  • Indirect reference counting

4. Explain how to add controls dynamically to the form using C#.NET.

The following code can be called on some event like page load or onload of some image or even a user action like onclick

 protected void add_button(Button button)
        panel1.Controls.Add(button); // Add the control to the container on a page
   catch (Exception ex)
         label1.Text += ex.Message.ToString();

5. What are Extender provider components? Explain how to use an extender provider in the project.

An extender provider is a component that provides properties to other components.
Implementing an extender provider:

  1. Use the ProvidePropertyAttribute, which specifies the name of the property that an implementer of IExtenderProvider provides to other components, attribute to specify the property provided by your extender provider.
  2. Implement the provided property.
  3. Track which controls receive your provided property.
  4. Implement the IExtenderProvider, which defines the interface for extending properties to other components in a containe, interface.

6. Describe the configuration files in .Net. What are different types of configuration files in .Net framework?

The Machine.Config file, which specifies the settings that are global to a particular machine.
This file is located at the following path:
\WINNT\Microsoft.NET\Framework\[Framework Version]\CONFIG\machine.config The simplest way to add application-specific settings into an application configuration file is to use an application configuration file.
The file is an XML file and contains add elements with key and value attributes.



The authentication section controls the type of authentication used within your Web application Windows, Forms or Passport type of authentication can be defined. Eg:

 or  tags can be used with authorization to allow or deny access to your web application to certain users or roles,

7. Describe the accessibility modifier "protected internal" in C#.

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.

8. What is the difference between Debug.Write and Trace.Write? When should each be used?

Debug.Write : Debug Mode, Release Mode (used while debuging a project)
Trace.write : Release Mode (used in Released verion of Applications)

9. Explain the use of virtual, sealed, override, and abstract.

The virtual keyword enables a class to be overridden. If it has to be prevented from being overridden, then the sealed keyword needs to be used. If the keyword virtual is not used, members of the class can even then be overridden. However, its usage is advised for making the code meaningful.
The override keyword is used to override the virtual method in the base class. Abstract keyword is used to modify a class, method or property declaration. You cannot instantiate an abstract class or make calls to an abstract method directly.
An abstract virtual method means that the definition of the method needs to be given in the derived class.

10. What benefit do you get from using a Primary Interop Assembly (PIA)?

A primary interop assembly contains type definitions (as metadata) of types implemented with COM. Only a single PIA can exist, which needs to be signed with a strong name by the publisher of the COM type library. One PIA can wrap multiple versions of the same type library. A COM type library imported as an assembly can be a PIA only if it has been signed and published by the same publisher. Therefore, only the publisher of a type library can produce a true PIA, that can be considered as the unit of an official type definition for interoperating with the underlying COM types.

2 Komentar untuk "C#.NET Interview Question & Answer"

its not enough questions to face interview...

yes, i know if you have any C#.net Interview Question along with Answer send us ...

Back To Top