Tuesday, October 14, 2008

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).


How do you inherit from a class in C#?

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


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

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()

{

}

}


Can I define a type that is an alias of another type (like typedef in C++)?

Not exactly. You can create an alias within a single file with the "using" directive: using System; using Integer = System.Int32; // aliasBut you can't create a true alias, one that extends beyond the file in which it is declared. Refer to the C# spec for more info on the 'using' statement's scope.


Is it possible to have different access modifiers on the get/set methods of a property?

No. 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.

0 comments: