.NET Framework Interview Questions and Answers (547) - Page 12

what is Reflection?

Reflection is the feature in .Net, which enables us to get some information about object in runtime. That information contains data of the class. Also it can get the names of the methods that are inside the class and constructors of that object.

program should use the reflection derived from namespace System.Reflection .
using reflection can dynamically load assembly.
Which file sets the environment variables for Visual Studio?

The vsvars32.bat sets the environment variables for Visual Studio. You can find it from %Microsoft Visual Studio 2008\Common7\Tools\vsvars32.bat.

When you start the Visual Studio 2008 command prompt it automatically runs vsvars32.bat.
Which namespace provides classes for Regular Expression?

System.Text.RegularExpressions namespace provides classes for Regular Expression
What is the use of System.SystemException namespace?

System.SystemException provide different classes to handle fatal as well as non fatal errors.
Which class is the base class of all the exception classes?

System.Exception class is the base class of all the exception classes in .NET.
Which namespace is used to work with RSS feeds in .NET?

System.ServiceModel.Syndication namespace is used to work with RSS feeds in .NET.
Which namespace is used to create an Exception Tree?

System.Data.Common.CommandTree namespace provide classes to create an Exception Tree.
How can we open the disassembler from Dot Net Command prompt ?

ILDASM (Intermediate Language Disassembler) is installed along with Visual Studio. You can found it inside the Visual Studio SDK Folder.
Version folder name will be depends on your .NET Framework version.
As for Example,
C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\
Now With the help of command
ILDASM
we can open it from Visual Studio Command Prompt.

We can open the ibuilt disassembler provided with framework to check the assembly information.


Modified By :
Moderator 3
Sorting on a Datatable

By using a datatable we can sort the data with out going for a dataview.

DataTable dt = new DataTable();
dt.Select(" select criteria if any " , " sort string ")
What is a DependencyProperty and How to implement it?

DependencyProperty is set to enable declarative code to alter the properties of an object which reduces the data requirements by providing a more powerful notification system regarding the change of data in a very specific way. In .NET, there are two types of properties. One is the normal property & another is the DependencyProperty which has added functionality over the normal property.

Now, let us discuss on how to implement such DependencyProperty to give a powerful notification on data change:

First of all, implement the UserControl class from INotifyPropertyChanged interface:

public partial class MyUserControl : UserControl, INotifyPropertyChanged 

{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}


Create your own normal Property, lets say the name of the property is “Caption”.

public string Caption 

{
get { return GetValue(CaptionProperty).ToString(); }
set { SetValue(CaptionProperty, value); }
}


Now, register the DependencyProperty to the CLR by calling the Register method by passing the property field that you used to store the data in earlier step:

public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register("Caption", typeof(string), typeof(MyUserControl), new PropertyMetadata(string.Empty, OnCaptionPropertyChanged));



The name of the identifier field of the DependencyProperty will be same as you used in the property after appending “Property” at the end. In this example, our Property name is “Caption”, hence our identifier field name is “CaptionProperty”. Add the PropertyMetaData with default value & callback event handler within the Register method as mentioned in the above code. Mark the identifier as static & readonly so that this will be unique to the CLR.

Now, implement the OnCaptionPropertyChanged event handler:

private static void OnCaptionPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) 

{
MyUserControl myUserControl = dependencyObject as MyUserControl;
myUserControl.OnPropertyChanged("Caption");
myUserControl.OnCaptionPropertyChanged(e);
}

private void OnCaptionPropertyChanged(DependencyPropertyChangedEventArgs e)
{
txbCaption.Text = Caption;
}


The implementation of the DependencyProperty is complete. You can either call it from XAML:

<local:MyUserControl Caption="My First Dependency Property Example" />



or from Code behind:

MyUserControl myUserControl = new MyUserControl(); 

myUserControl.SetValue(MyUserControl.CaptionProperty, "My First Dependency Property Example");

What is Covariance and Contravariance ?

Assigning a string to an object from specific type to a more general type is called covariance.

In contrast, assigning an array of objects to an array of strings, from general type to a more specific type, is referred to as contravariance.
What is equivalent for regsvr32.exe in .NET?

In .NET we have regasm to register and unregister assemblies through .NET.
What are the Expansions of MSIL, JIT, CLR, CTS, CLS, RCW?

1. MSIL - Microsoft Intermediate Language.
2. JIT - Just-In-Time compiler .
3. CLR - Common Language Runtime.
4. CTS - Common Type System.
5. CLS - Common Language Specification.
6. RCW - Runtime Callable Wrapper.
Which namespace contains the classes that required to serialize an object? Explain Object Serialization?

System.Runtime.Serialization

Object serialization is the process of reducing an object instance into a format that can be either stored to disk or transported over a network.
Explain how to retrieve resources using ResourceManager class?

ResourceManager class is used to retrieve resources at run time.
• Create a ResourceManager with resource file name and the resource assembly as parameters.
• After having created, you can use ResourceManager.GetString method to retrieve a string.
• Use the ResourceManager.GetObject method to retrieve images and objects from a resource file.
What is code security? What are the types?

.NET framework provides the security features to secure code from unauthorized users.

There are two types of code security:
Role based security: This authorizes user.
Code access security: This protects system resources from unauthorized calls.
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