Hello- Please help me with the following questions, if possible, please also provide some explanations--thanks in advance:
1) Assuming that "valid connection string" is a valid connection string, what will be the output of the following code? If the code cannot compile, please state why.
the same rules apply to this question as for the one above
using(SqlConnection sqlConn = new SqlConnection("valid Connection string"))
{
System.Diagnostics.Debug.WriteLine("Opening a connection");
sqlConn.Open();
System.Diagnostics.Debug.WriteLine("Connection Opened");
sqlConn.Close();
System.Diagnostics.Debug.WriteLine("Connection Closed");
}
if(sqlConn == null)
System.Diagnostics.Debug.WriteLine("Connection State is NULL");
else
System.Diagnostics.Debug.WriteLine("Connection State:" + sqlConn.ConnectionState);
2)The following code needs to generate a string of 1000 alternating '+' and '-' characters
Rewrite this code to make it more efficient (Note: You can use different data types than the ones present)
string htmlOutput = string.Empty;
for(int itemIndex = 0; itemIndex < 1000; itemIndex++)
{
if( itemIndex % 2 == 0)
htmlOutput += "+";
else
htmlOutput += "-";
}
3)Assuming that CustomException is defined, what will be the output of the following code?
try
{
throw new CustomException("Something went wrong");
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine("Generic Exception has been triggered");
}
catch(CustomException ex)
{
System.Diagnostics.Debug.WriteLine("Custom Exception has been triggered");
}
4) What will be the difference in behavior between the lines marked 'a' and 'b' during runtime? (Assume that CustomClass is a defined class)
object objClass = new object();
CustomClass myClass1 = objClass as CustomClass; //a
CustomClass myClass2 = (CustomClass)objClass; //b
5) Assuming you have the following class:
public class MyClass
{
public MyClass()
{
}
public string DoNothing(string someParameter)
{
System.Diagnostics.Debug.WriteLine(someParameter);
}
}
How would you call the DoNothing function asynchronously and provide a callback?
6) What is the difference between a Monitor and a Semaphore?
7) Architectural Question: If you have pages that perform heavy DB or File I/O, what could be done to help increase the overall performance of the application? (Asp.net only! Assume all non asp.net factors have been optimized to the max)
8) What is the difference between the following 2 statements?
try
{
throw new ApplicationException("None");
}
catch(Exception ex)
{
throw ex;
}
try
{
throw new ApplicationException("None");
}
catch(Exception ex)
{
throw;}
9) What is the difference between a List and a LinkedList?
10) Assume that you retrieve a list of 1,000,000 Person objects from a database that contain the SocialSecurityID, First and Last name properties. Which collection class would you use to store and allow for quick lookup of Person objects based on the SocialSecurityID field?
dilipv vishwakarmaPosted Feb 29, 2008, 2:51 AM
hi there,
Answer for 1st question as follow.
Since you are using System.Diagnostics.Debug.WriteLine then you are compiling your project. System.Diagnostics.Debug.WriteLine is used to print any values into the output window while debugging.
It starts compiling but cant complete due to showing values in output window while debugging.
Answer for 2nd question as follow.
string htmlOutput = string.Empty;
for(int itemIndex = 0; itemIndex < 500; itemIndex++)
{
htmlOutput += "+-";
}
Answer for 4th question as follow.
object objClass = new object();
CustomClass myClass1 = objClass as CustomClass; //a
CustomClass myClass2 = (CustomClass)objClass; //b
Statement a uses "as" operator to perform conversions between compatible reference types.The as operator is like a cast operation. However, if the conversion is not possible, as returns null instead of raising an exception.
Statement b uses explicit conversion to perform conversions between 2 user defined types.
The conversion operator converts from a source type to a target type. The source type provides the conversion operator. Unlike implicit conversion, explicit conversion operators must be invoked by means of a cast. If a conversion operation can cause exceptions or lose information, you should mark it explicit. This prevents the compiler from silently invoking the conversion operation with possibly unforeseen consequences.
Answer for 5th question as follow.
It won't compile because DoNothing doesn't return anything.
public string DoNothing(string someParameter)
{
System.Diagnostics.Debug.WriteLine(someParameter);
}
Answer for 6th question as follow.
Semaphores : -
Condition Variables Can be used anywhere in a program.
Wait() does not always block the caller (i.e., when the semaphore counter is greater than zero).
Signal() either releases a blocked thread, if there is one, or increases the semaphore counter.
If Signal() releases a blocked thread, the caller and the released thread both continue.
Monitor :-
Condition Variables Can only be used in monitors.
Wait() always blocks the caller.
Signal() either releases a blocked thread, if there is one, or the signal is lost as if it never happens.
If Signal() releases a blocked thread, the caller yields the monitor (Hoare type) or continues (Mesa Type). Only one of the caller or the released thread can continue, but not both.
Answer for 9th question as follow.
An list used an array for internal storage. This means it's fast for random access (e.g. get me element #999), because the array index gets you right to that element. But then adding and deleting at the start and middle of the list would be slow, because all the later elements have to copied forward or backward.
LinkedList is made up of a chain of nodes. Each node stores an element and the pointer to the next node. A singly linked list only has pointers to next. A doubly linked list has a pointer to the next and the previous element. This makes walking the list backward easier.
Hope this will help you.
Thanks & Regards
Dilipv
Programmer
SharePoint Consulting
Len LPosted Feb 28, 2008, 7:28 PM
forgot, for question 2
I would re-write to be
int i=0;
string s = null;
while(i < 500)
{
s += "+-";
i++;
}
Len LPosted Feb 28, 2008, 7:22 PM