ASP.NET Interview Questions and Answers (1544) - Page 60

How to reassign values to Dictionary?

Dim dict As New Dictionary(Of String, Integer)

dict.Add("1", 100)
dict.Add("2", 200)

dict("2") = 300


dictionary key "1" have 2 values 100,300
Hot to avoid exception if we are adding items into Dictionary?

Always check ContainsKey method of Dictionary to avoid exceptions.

If (Not dict.ContainsKey(Key)) Then

dict.Add(Key,Value)
End If


It checks whether key is there in a dictionary or not.
What is the Namespace to work with generic collections i.e. List,SortedList?

We have to import System.Collections.Generic Namespace to work with generic collections.
What is the use of Sort method in List collection?

Sort method is used for Sorting List collection Items in Ascending Order.

For Example:-
List<int> lst = new List<int>();

lst.Add(2);
lst.Add(1);

lst.Sort();

foreach (int item in lst)
{
Response.Write(item);
}


Output will be 12
How to remove all List collection items?

We can use Clear method to clear all items from a List collections.

For Example:-

list.Clear();


Here,list is my List collection.
How to remove particular items from List collection?

There is a Remove method of List collection,we pass List item value to Remove method depends upon data-type meaning that if collection is of Integer type then we have to pass numeric value to Remove method.

For Example:-
List<int> lst = new List<int>();

lst.Remove(int item);

List<string> lst = new List<string>();
lst.Remove(string item);

What are the new features introduced in .net framework 4.5.1?

Some new features have been introduced in .net framework 4.5.1 along with the improvements under Application features and degubbing.

Improvements under debugging:
1.64-bit edit and continue support in Visual studio 2013.
2.Checking the return value of the method using Autos window as well as pseudo variable $ReturnValue.
3.Async debugging enhancements.
4.Connection resiliency.

Improvements under Application performance:
1.Application suspension.
2.Large-Object heap compaction on demand.
3.Multi-core JIT Improvements.
What does the statement System.exit(0) indicate?

When we write System.exit(0) at the end of try block, the control immediately goes out of the program and hence the finally block will not get executed.
When to use .toString() and Convert.ToString()?

The difference is that when we .toString, it will not handle nulls and hence throws an NULL reference exception error.
Whereas the Convert.ToString() handles the nulls.
Hence it is always better to use Convert.ToString().
What is hiding and shadowing?

Shadowing is a vb.net concept by which we can provide new implementation for base class member without overriding the member. We can shadow abase class member in the derived class by using Shadows keyword. Method sigature, access level and return type of the shadowed member can be different than the base class.

Hiding
is a c# concept by which we can provide a new implementation for the base class member without overriding the member. A base class member can be hided in the derived class using the new keyword. Method signature, access level and return type of the hidden member should be same as the base class member.
What is the use of Display property of all validation controls?

Display property is used to show or hide validation controls on the Page.It has 3 sub-type value as Static,Dynamic and None.By-default value is Static.When None is applied,then validator controls will be hidden means will not display on the Page.
When Dynamic value is applied then whatever validation controls are there on a page for a specific Textbox control,will shift left side means will not take any space on the page.
How to validate only characters will be allowed in Textbox?

We will use Regular Expression Validator control to validate Textbox.Below codd will allow only characters with no spaces.

<asp:TextBox runat="server" Id="txt_first_name" />


<asp:RegularExpressionValidator runat="server" id="rex_first_name" ControlToValidate="txt_first_name" ValidationExpression="^[a-zA-Z]$" ErrorMessage="Only Characters Allowed" />

How to validate only characters along-with space will be allowed in Textbox?

<asp:TextBox runat="server" Id="txt_first_name" />


<asp:RegularExpressionValidator runat="server" id="rex_first_name" ControlToValidate="txt_first_name" ValidationExpression="^[a-zA-Z ]$" ErrorMessage="Only Characters and Space Allowed" />

How to validate alpha-numeric along-with space will be allowed in a Textbox?

<asp:TextBox runat="server" Id="txt_policy_code" />


<asp:RegularExpressionValidator runat="server" id="rex_policy_code" ControlToValidate="txt_policy_code" ValidationExpression="^[a-zA-Z0-9 ]$" ErrorMessage="Only Alpha-Numeric and Space Allowed" />

How to update page data automatically into your application when you update it from another application using the same database without refreshing the page?

In you code put the timer control,
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="10000">
</asp:Timer>

Specify the interval for how much interval the page data should get automatically updated.

Then in the onTick event,
write the code to bind the data from your database.

Then even though your updating the content from your side, the user who is viewing your page currently will get any error, and content gets updated automatically
How can you define Delay signing?

Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development.
What is meant by satellite assembly?

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.
Can you call a native function that is exported from a dll, if so how?

Here’s a quick example of the DllImport attribute in action:

using System.Runtime.InteropServices; \
class C
{
[DllImport(\"user32.dll\")]
public static extern int MessageBoxA
(int h, string m, string c, int type);
public static int Main()
{
return MessageBoxA(0, \"Hello World!\", \"Caption\", 0);
}
}

This example shows the minimum requirements for declaring a C# method that is implemented in a native DLL. The method C.MessageBoxA() is declared with the static and external modifiers, and has the DllImport attribute, which tells the compiler that the implementation comes from the user32.dll, using the default name of MessageBoxA.
Can we have different access modifiers for the get and set methods? Justify your answer?

The answer is absolutely No because the access modifier on a property applies to both its get and set accessors. What you need to do if you want them to be different is make the property read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property.
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