C# Interview Questions and Answers (958) - Page 13

How to add controls dynamically to the form using C#.NET?

Below is the code that can be called on some events like page load or onload or even some user action like onclick.

protected void add_button(Button btn)

{
try
{
panel1.Controls.Add(btn); // Add the control to the container on a page
}
catch (Exception ee)
{
lblError.Text = ee.Message.ToString();
}
}

Explain what is Extender provider component? How to use this in the project?

This is a component which provides properties and features to other components or controls. This mechanism is usually used in windows forms applications. The examples of extender provider components are ToolTip, HelpProvider, and ErrorProvider etc.

Use an extender provider in your project:
• With the help of ProvidePropertyAttribute, you can specify the name of the property that an implementer of IExtenderProvider provides to other controls, attribute to specify the property.
• Then use the provided property and try to find which control receives your provided property.
• After that use IExtenderProvider, this defines the interface for extending properties to other components.
What is the difference between Debug.Write and Trace.Write?

The Debug.Write will work while the application is in both Debug Mode and Release Mode. This is normally used while you are going to debug a project. This will not be work when you will define some debug points to your project.

But the Trace.write will work while the application is only in Release Mode. This is used in released version of an application. This will compiled when you will define debug points in your project.
What is the use of virtual, sealed, override, and abstract?

• The use of virtual keyword is to enable or to allow a class to be overridden in the derived class.
• The use of sealed keyword is to prevent the class from overridden i.e. you can’t inherit sealed classes.
• The use of override keyword is to override the virtual method in the derived class.
• The use of abstract keyword is to modify the class, method, and property declaration. You cannot directly make calls to an abstract method and you cannot instantiate an abstract class.
What is Primary Interop Assembly (PIA)?

This is an assembly that contains the type definitions that is metadata of types, which is implemented with COM. This can snatch up multiple versions of the same type library. These are needs to be signed with a strong name by the publisher of the COM type library. This library imported as an assembly when it has been signed.
What is the use of static members in C#.NET?

The static members are the members which are not associated with a particular occurrence of any class. To implement this you have to use the keyword "static" before any member function. They can't access to non-static members as they are not associated with object instances.
What is implementation inheritance and interface inheritance?

• When a class is derived from another class in such a way that it will inherit all its members to its corresponding derived class, then it is implementation inheritance.

• When a class inherits only the signatures of the functions from its corresponding base class, then it is interface inheritance.
What is C#.NET Generics?

When the C#.NET Generics are instantiated, then the CLR compiles and stores the information related to the generic types that is it refers to the location in memory of the reference type to which it is bound for all the instances. Here the classes and methods can treat the values of different types uniformly.

The main purpose of using this is to facilitate type safety, improves performance and reduces code. It also promotes the usage of parameterized types in an application.
What is structs?

Structs are similar to a class.Some of the points listed below:

• A struct is a value type.
• The structs doesn’t support inheritance other than implicitly deriving from object.
• A struct can have the members like parameterless constructor, a finalizer, virtual members etc.
What is enum?

A enum is nothing but a special value type which specifies a group of named numeric constants.

For Example:
public enum cube {Length, Height, Width}


We can use the enum type as
cube len = cube.Length;

bool isLength = (len == cube.Length);

What is the difference between object pooling and connection pooling?

In case of object pooling, you can control the number of connections. In this case the pool will decide whether the maximum is reached or not for creation of objects. If it reached to the maximum level then the next available object will returned back. The drawback is, it increases the time complexity for heavy objects.

In case of connection pooling, you can control the maximum number of connections reached. When you are using this pool, since there is nothing in the pool, still it will create connection on the same thread.
Difference between static variable and constant in c#?

Static Variable:
1.Variable set at run time
2.Can be assigned for reference types.
3.Initialized on constructors

Constant:
1.Variable set at compile time itself.
2.Assigned for value types only
3.must be initialized at declaration time
4.only primitive data types.
Why we are using System.Environment class?

The aim of using System.Environment class is to get the command-line arguments.
This class also helps us to retrive the environment variable settings for a particular
contents of the call stack. It can also find the time of last system boot and
version of the CLR.
What is virtual function?

To provide a specialized implementation in a class, we can mark the member function name as virtual which can be overridden in the subclasses. We can declare methods, indexers, events, and properties as virtual in a class.

It implements the concept of polymorphism. If a class that overrides the virtual method then it has to use the override keyword.
What is ILDASM?

The ILDASM stands for Intermediate Language Disassembler . This is a de-compiler which helps to get the source code from the assembly.

This ILDASM converts an assembly to instructions from which source code can be obtained.

The ILDASM can analize the .dll or .exe files and converts into human readable form. This is used to examine assemblies and understanding the assembly capability.
What is Satellite Assembly ?

When we create a Multi-Cultural or Multi-lingual Application and if we want to distribute this application seperately from local modules , the local assemblies that change this core application are said to be Satellite Assemblies .

To create the satellite assemblies, We will use Assembly Linker i.e al.exe utility to link the resource file to an assembly.

For example :

al /t:library /embed:strings.en.resources /culture:en /out:MyAppSrikanth.resources.dll

The /t option ----> will direct Assembly Linker to build a library,
and the /embed ----> option identifies the file to be linked.
Which one of the following language is not included in the installation of .net Framework ? (Default Installation)

NOTE: This is objective type question, Please click question title for correct answer.
Can we have 2 applications run on a same machine using different Framework Versions ?

NOTE: This is objective type question, Please click question title for correct answer.
Which Object contains all the properties and methods for every Asp.net page ?

NOTE: This is objective type question, Please click question title for correct answer.
What is Process Identifier?

The Process Identifier is used to identify a process in an Operating System. It is uniquely assigned integer used for troubleshooting a system. Basically this helps to diagnosing the problems in systems which performs more than one task or runs more than one application at a time.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories