ASP.NET Test - 10

1)   You need to select a class that is optimized for key - based item retrieval from both small and large collections. Which class should you choose?

a. OrderedDictionary class
b. HybridDictionary class
c. ListDictionary class
d. Hashtable class
Answer  Explanation 

ANSWER: HybridDictionary class

Explanation:
HybridDictionary classes optimized for key-based item retrieval from both small and large collections. If the numbers of items are less then it works as ListDictionary and only when the list becomes too large it converts automatically into a Hashtable internally.
If you do not know how large your collection is, then HybridDictionary class should be used.


2)   You need to identify a type that meets the following criteria:

• Is always a number.
• Is not greater than 65,535.

Which type should you choose?


a. System.UInt16
b. int
c. System.String
d. System.IntPtr
Answer  Explanation 

ANSWER: System.UInt16

Explanation:
The maximum value of System.UInt16 is 65535 so you can store more than this value.


3)   Which of the following is dictionary object?


a. HashTable
b. SortedList
c. NameValueCollection
d. All of the above
Answer  Explanation 

ANSWER: All of the above

Explanation:
HashTable, SortedList, NameValueCollection are dictionary objects because it store data in key-value form.

Example:
Hashtableht = new Hashtable();
ht["CompId"] = "1";
ht["CompName"] = "CareerRide";
foreach (DictionaryEntryob in ht)
{
Console.WriteLine(ob.Key+" : "+ob.Value);
}


4)   You want to configure the application to use the following authorization rules in web.config file.

• Anonymous users must not be allowed to access the application.
• All employees except ABC must be allowed to access the application.


a.
<authorization>
<deny users=”ABC”>
<allow users=”*”>
<deny users=”?”>
</authorization>
b.
<authorization>
<allow users=”*”>
<deny users=”ABC”>
<deny users=”?”>
</authorization>
c.
<authorization>
<allow users=”ABC”>
<allow users=”*”>
</authorization>
d.
<authorization>
<deny users=”ABC”>
<deny users=”?”>
<allow users=”*”>
</authorization>
Answer  Explanation 

ANSWER:
<authorization>
<deny users=”ABC”>
<deny users=”?”>
<allow users=”*”>
</authorization>

Explanation:
First you deny user ABC. Then you deny anonymous users access by writing <deny users=”?”>. And last we allow to all other users access. This is proper order of the elements for the requirements of this scenario.


5)   An assembly must have an permission to connect with web server is?

a. socketPermission
b. DnsPermission
c. WebPermission
d. TCPPermission
Answer  Explanation 

ANSWER: WebPermission

Explanation:
No explanation is available for this question!


6)   Thread class has the following property.

A. ManagedThreadID
B. IsBackground
C. IsBackgroundColor
D. Abort


a. 1, 2
b. 1, 4
c. 4
d. 1 ,2, 4
Answer  Explanation 

ANSWER: 1, 2

Explanation:
ManagedThreadID and IsBackground are the properties of Thread class.
ManagedThreadID is used to get Gets a unique identifier for the current managed thread.
IsBackground property is used to gets or sets a value to check whether or not a thread is a background thread


7)   Which delegate is required to start a thread with one parameter?

a. ThreadStart
b. ParameterizedThreadStart
c. ThreadStartWithOneParameter
d. None of the above
Answer  Explanation 

ANSWER: ParameterizedThreadStart

Explanation:
ParameterizedThreadStart is a delegate that refers to a method that have single parameter.

Example:
class Program
{
static void Main(string[] args)
{
ParameterizedThreadStartts = new ParameterizedThreadStart(Counting);
Thread obj = new Thread(ts);

obj.Start("careerride");

}
static void Counting(Object obj)
{
stringstr=(string)obj;
Console.WriteLine("Welcome at "+str);
for (int i = 1; i <= 10; i++)
{
Console.WriteLine("Count: {0}", i);
Thread.Sleep(10);
}
}
}


8)   For locking the data with synchronization which class will be used?

a. Lock
b. Moniter
c. SyncLock
d. Deadlock
Answer  Explanation 

ANSWER: Moniter

Explanation:
By using Moniter class a block of code can be access by one thread at a time. Moniter.Enter() method allows only one thread to access the resource.

Example:
public void ShowNumbers()
{
Monitor.Enter(this);
try
{
for (int i = 0; i < 5; i++)
{
Thread.Sleep(100);
Console.Write(i + ",");
}
Console.WriteLine();
}
finally
{
Monitor.Exit(this);
}
}


9)   How many readers can simultaneously read data with ReaderWriterLock if there is no writer locks apply?

a. 9
b. 11
c. 13
d. No Limit
Answer  Explanation 

ANSWER: No Limit

Explanation:
There is no limit for number of users to access the data if ReaderWriterLock is applied. By using ReaderWriterLock you can synchronize access to a resource. It allows concurrent read access to multiple users. ReaderWriterLock class is available in System.Threading namespace.


10)   Which of the following are value types?

a. String
b. System .Value
c. System.Drawing
d. System.Drawing.Point
Answer  Explanation 

ANSWER: System.Drawing.Point

Explanation:
There are two types are available in C#. Value Type and Reference Type. Value type are allocated on stack and reference types are allocated on managed heap. Predefined datatypes, structures, enums are value types. Class, Sting, Object etc are reference types. In the above example Point is struct so it is value type.


11)   Which of the following are reference types?

a. String
b. Exception
c. Class
d. All of the above
Answer  Explanation 

ANSWER: All of the above

Explanation:
No explanation is available for this question!


12)   Why should you write the cleanup code in Finally block?

a. Compiler throws an error if you close the connection in try block.
b. Resource cannot be destroyed in catch block.
c. Finally blocks run whether or not exception occurs.
d. All of the above
Answer  Explanation 

ANSWER: Finally blocks run whether or not exception occurs.

Explanation:
The finally block always executes whether exception occurs or not. Finally block run when control leaves a try statement. You can write all cleanup code in finally block.

Example:
class Program
{
staticint a = 10, b = 0, c;
static void Main(string[] args)
{

try
{
c = a / b;
}
finally
{
Console.WriteLine(c);
}

}
}


13)   When the garbage collector runs.

a. It runs automatically
b. EveryDay
c. Every alternate day
d. When IIS restart.
Answer  Explanation 

ANSWER: It runs automatically

Explanation:
We create the object, use it and generally forget to delete. Garbage collector is automatic memory management process that releases the memory used by the objects. Garbage collector runs automatically and it checks for objects in the managed heap that are no longer being used by the application and performs the necessary action to regain memory.
It allows us to develop an application without having worry to free memory.


14)   Which of the following is true ?

1. AJAX is a platform-independent technology
2. AJAX can work with web application
3. AJAX can only work with ASP.NET
4. AJAX is a platform-dependent technology


a. 1, 2
b. 1,2,3
c. 1,3,4
d. None of the above
Answer  Explanation 

ANSWER: 1, 2

Explanation:
AJAX is a platform-independent technology that works with Web applications. Ajax (Asynchronous JavaScript And XML) enables your client - side web pages to exchange data with the server through asynchronous calls. By using AJAX you can create flicker - free pages that enable you to refresh partial page without a full reload and without affecting other parts of the page.


15)   Which control is required for every page that have AJAX Extensions for ASP.NET?

a. UpdatePanel
b. ScriptManager
c. ContentPanel
d. None of the above
Answer  Explanation 

ANSWER: ScriptManager

Explanation:
ScriptManager control is required for every page that have AJAX Extensions for ASP.NET The ScriptManager control manages the communication between the client page and the server.You can directly drag and drop this control on content page. It does not have a visual representation. It only used to manage AJAX processing. You cannot use more than one ScriptManager control on single web page.

<asp: ScriptManager ID=" ScriptManager1 " runat=" server ">
</asp: ScriptManager>


16)   AnUpdatePanel control defined on a page. Button control is placed outside of the UpdatePanel. How to cause the UpdatePanel to execute an update.

a. Set the Trigger attribute of the UpdatePanel to the ID of the Button control.
b. Set the AsyncPostBackTrigger attribute of the Button control to the ID of theUpdatePanel.
c. Place the button control on the update panel without script manager.
d. Add an AsyncPostBackTrigger control to the Triggers section of the UpdatePanel. Set the ControlID attribute of the AsyncPostBackTrigger control to the ID of the Button control.
Answer  Explanation 

ANSWER: Add an AsyncPostBackTrigger control to the Triggers section of the UpdatePanel. Set the ControlID attribute of the AsyncPostBackTrigger control to the ID of the Button control.

Explanation:
To connect a control that is outside an UpdatePanel and you want that this outside control should trigger the update then you should register it as an asyncPostBackTrigger in the Triggers section of the UpdatePanel markup.

<asp:UpdatePanel ID="UpdatePanelVendors" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>


17)   Which method is used to dynamically register client script from code?

a. Page.ClientScript.RegisterClientScriptBlock
b. RegisterScript
c. Page.ClientScript
d. None of the above
Answer  Explanation 

ANSWER: Page.ClientScript.RegisterClientScriptBlock

Explanation:
Page.ClientScript.RegisterClientScriptBlock method is used to dynamically register client script from code.


18)   Which interface you will use wrap an AJAX client control into a custom server control?

a. IScriptManager
b. IScriptControl
c. IScriptAJAX
d. None of the above
Answer  Explanation 

ANSWER: IScriptManager

Explanation:
No explanation is available for this question!


19)   What is jQuery?

1. jQuery is an open source library
2. It works client side.
3. jQuery is java technology.


a. 1, 2
b. 1, 2, 3
c. 1, 3
d. None of the above
Answer  Explanation 

ANSWER: 1, 2

Explanation:
jQuery is java script library that works on client side. By using jQuery it is much easier to use JavaScript on your website.
The main feature of jQuery is as follows

• HTML / DOM manipulation
• CSS manipulation
• HTML event methods
• Animations
• AJAX


20)   If you must use a user name and password to connect to a database, where should you store the sensitive information?

a. Compiled in the application
b. In an encrypted application configuration file
c. In a resource file deployed with the application
d. In the registry
Answer  Explanation 

ANSWER: In an encrypted application configuration file

Explanation:
If your connection string contains sensitive information then encrypted application configuration file by using RsaProtectedConfigurationProvider:


21)   What is the recommended method for securing sensitive connection string information?

a. Encrypting the data in the application configuration file
b. Using a code obfuscator
c. Using Integrated Security (Windows Authentication)
d. Querying the user for his or her credentials at run time
Answer  Explanation 

ANSWER: Using Integrated Security (Windows Authentication)

Explanation:
No explanation is available for this question!


22)   What are the element of code access security?

a. Evidence,Permission
b. SQLSecurity
c. UserInterface
d. SQL Injection
Answer  Explanation 

ANSWER: Evidence,Permission

Explanation:
Code access security consists of the following elements:

• permissions
• permission sets
• code groups
• evidence
• policy


23)   What is Caspol?

a. Command line tool
b. Code access security policy tool
c. Case Tool
d. Command line tool & Code access security policy tool
Answer  Explanation 

ANSWER: Command line tool & Code access security policy tool

Explanation:
Caspol is command line code access security policy tool. By using this tool administrator can modify security policy for the following level.

Machine policy level.
User policy level.
Enterprise policy level.


24)   Which data provider gives the maximum performance from a connection to SQL Server?

a. The OLE DB data provider.
b. The JDBC data provider.
c. The SqlClient data provider.
d. The Oracle data provider
Answer  Explanation 

ANSWER: The SqlClient data provider.

Explanation:
The SqlClient data provider gives the maximum performance from a connection to SQL Server.
Data provider works as a bridge between an application and a data source.SQL Server.NET Data Provider available in the System.Data.SqlClient namespace.


25)   Which CommandType value is incorrect?

a. StoredProcedure
b. TableDirect
c. TableSchema
d. Text
Answer  Explanation 

ANSWER: TableSchema

Explanation:
The TableSchema value is wrong because it is not a CommandType enumeration value.


26)   Which SqlCommand execution returns the value of the first column of the first row from a table?

a. ExecuteNonQuery
b. ExecuteReader
c. ExecuteXmlReader
d. ExecuteScalar
Answer  Explanation 

ANSWER: ExecuteScalar

Explanation:
EecuteScalar method of SqlCommand object returns the value of the first column of the first row from a table.
The common methods of command abject are as follows.

• ExecuteReader: This method works on select SQL query. It returns the DataReader object. Use DataReader read () method to retrieve the rows.
• ExecuteScalar: This method returns single value. Its return type is Object.If you call ExecuteScalar method with a SQL statement that returns rows of data, the query returns only the first column of the first row.
• ExecuteNonQuery: If you are using Insert, Update or Delete SQL statement then use this method. Its return type is Integer (The number of affected records).


27)   Which SqlCommand execution returns the number of effected records in the table?

a. ExecuteNonQuery
b. ExecuteReader
c. ExecuteXmlReader
d. ExecuteScalar
Answer  Explanation 

ANSWER: ExecuteNonQuery

Explanation:
EecuteScalar method of SqlCommand object returns the value of the first column of the first row from a table.
The common methods of command abject are as follows.

• ExecuteReader: This method works on select SQL query. It returns the DataReader object. Use DataReader read () method to retrieve the rows.
• ExecuteScalar: This method returns single value. Its return type is Object.If you call ExecuteScalar method with a SQL statement that returns rows of data, the query returns only the first column of the first row.
• ExecuteNonQuery: If you are using Insert, Update or Delete SQL statement then use this method. Its return type is Integer (The number of affected records).


28)   OleDbConnectionobject works with?

1. When connecting to an Oracle database
2. When connecting to an Office Access database
3. When connecting to SQL Server 6.x or later
4. When connecting to SQL Server 2000


a. 1, 2
b. 2, 3
c. 1, 3
d. 4
Answer  Explanation 

ANSWER: 2, 3

Explanation:
OleDbConnection object is used to connect to SQL Server 6.x or later. It is also used to connect with access database.
Example of connection string.
Provider = Microsoft.ACE.OLEDB.12.0;
Data Source = C:\myFolder\myAccessFile.accdb;
Persist Security Info = False;


29)   What is the minimal information needed by a connection string to open a connection to a SQL Server 2000 or SQL Server 2005 database?

1. A valid data source
2. A valid provider name
3. A valid file path
4. Appropriate credentials or Integrated Security settings


a. 1, 2
b. 1, 2, 3
c. 1, 3
d. 1, 4
Answer  Explanation 

ANSWER: 1, 4

Explanation:
A valid data source, appropriate credentials or Integrated Security settings needed by a connection string to open a connection to a SQL Server 2000 or SQL Server 2005 database.
Example:
String conString = "Data Source = PC name; Initial Catalog = your DataBasename;
Integrated Security = SSPI;"


30)   What happens when you call the Close method of a connection object?

1. The connection is destroyed.
2. The connection is returned to the connection pool.
3. The StateChangeevent is fired.
4. All non - committed pending transactions are rolled back.


a. 1, 2
b. 1,3
c. 2, 3, 4
d. All of the above
Answer  Explanation 

ANSWER: 2, 3, 4

Explanation:
When you call close method of a connection objectStateChange event is fired, non - committed pending transactions are rolled back and connection is returned to the connection pool.