Set - 5

Question 1 :

Can you change the value of a variable while debugging a C# application?

Answer :

Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.


Question 2 :

Are private class-level variables inherited?

Answer :

Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.


Question 3 :

Can you inherit multiple interfaces?

Answer :

Yes. .NET does support multiple interfaces.


Question 4 :

From a versioning perspective, what are the drawbacks of extending an interface as opposed to extending a class?

Answer :

With regard to versioning, interfaces are less flexible than classes. With a class, you can ship version 1 and then, in version 2, decide to add another method. As long as the method is not abstract (i.e., as long as you provide a default implementation of the method), any existing derived classes continue to function with no changes. Because interfaces do not support implementation inheritance, this same pattern does not hold for interfaces. Adding a method to an interface is like adding an abstract method to a base class--any class that implements the interface will break, because the class doesn't implement the new interface method.


Question 5 :

Which one is trusted and which one is untrusted?

Answer :

Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction


Question 6 :

What namespaces are necessary to create a localized application?

Answer :

System.Globalization, System.Resources.

 


Question 7 :

Does Console.WriteLine() stop printing when it reaches a NULL character within a string?

Answer :

Strings are not null terminated in the runtime, so embedded nulls are allowed. Console.WriteLine() and all similar methods continue until the end of the string.


Question 8 :

What is the advantage of using System.Text.StringBuilder over System.String?

Answer :

StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it is being operated on, a new instance is created.


Question 9 :

What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?

Answer :

SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it is a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.


Question 10 :

Why do I get a security exception when I try to run my C# app?

Answer :

Some security exceptions are thrown if you are working on a network share. There are some parts of the frameworks that will not run if being run off a share (roaming profile, mapped drives, etc.). To see if this is what's happening, just move the executable over to your local drive and see if it runs without the exceptions. One of the common exceptions thrown under these conditions is

System.Security.SecurityException.

To get around this, you can change your security policy for the intranet zone, code group 1.2, (the zone that running off shared folders falls into) by using the caspol.exe tool.


Question 11 :

Is there any sample C# code for simple threading? 

Answer :

Some sample code follows:

using System;
using System.Threading;
class ThreadTest{
	public void runme(){
		Console.WriteLine("Runme Called");
	}
	public static void Main(String[] args){
		ThreadTest b = new ThreadTest();
		Thread t = new Thread(new ThreadStart(b.runme));
		t.Start();
	}
}

 


Question 12 :

What is the difference between // comments, /* */ comments and /// comments?

Answer :

Single-line, multi-line and XML documentation comments.


Question 13 :

What is the difference between and XML documentation tag? 

Answer :

Single line code example and multiple-line code example.

Explain the three services model (three-tier application). Presentation (UI), business (logic and underlying code) and data (from storage or other sources). 

What are three test cases you should go through in unit testing? Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).


Question 14 :

How do you inherit from a class in C#?

Answer :

Place a colon and then the name of the base class. Notice that it is double colon in C++.


Question 15 :

How do I port "synchronized" functions from Visual J++ to C#?

Answer :

Original Visual J++ code:

public synchronized void Run(){
	// function body
}

Ported C# code:

class C{
	public void Run(){
		lock(this){
			// function body
		}
	}
	public static void Main() {}
}

 


Question 16 :

Can you declare an override method to be static if the original method is not static?

Answer :

No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override)


Question 17 :

What are the different ways a method can be overloaded?

Answer :

Different parameter data types, different number of parameters, different order of parameters.


Question 18 :

If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

Answer :

Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.


Question 19 :

What's a delegate?

Answer :

A delegate object encapsulates a reference to a method.


Question 20 :

What's a multicast delegate?

Answer :

A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.


Question 21 :

Which control cannot be placed in MDI?

Answer :

The controls that do not have events.


Question 22 :

What is the difference between proc. sent BY VAL and BY SUB?

Answer :

BY VAL: changes will not be reflected back to the variable.
By REF: changes will be reflected back to that variable.( same as & symbol in c, c++)


Question 23 :

Does C# support multiple-inheritance?

Answer :

No.


Question 24 :

Who is a protected class-level variable available to?

Answer :

It is available to any sub-class (a class inheriting this class).


Question 25 :

Are private class-level variables inherited?

Answer :

Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.