C#

How do you mark a method obsolete?

Assuming you’ve done a “using System;”: [Obsolete]

public int Foo() {…}

or [Obsolete("This is a message describing why this method is obsolete")]

public int Foo() {…}

Note: The O in Obsolete is capitalized.

How do you implement thread synchronization (Object.Wait, Notify,and CriticalSection) in C#

You want the lock statement, which is the same as Monitor Enter/Exit:

lock(obj)

{

// code

}

translates to: try

{

CriticalSection.Enter(obj);

// code

}

finally

{

CriticalSection.Exit(obj);

}

Where is the output of TextWriterTraceListener redirected?

To the Console or a text file depending on the parameter passed to the constructor.

How do you debug an ASP.NET Web application?

Attach the aspnet_wp.exe process to the DbgClr debugger.

What are three test cases you should go through in unit testing?

1. Positive test cases (correct data, correct output). 2. Negative test cases (broken or missing data, proper handling). 3. Exception test cases (exceptions are thrown and caught properly).

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

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

Is it possible to inline assembly or IL in C# code?

No.

Is it possible to have a static indexer in C#?

No. Static indexers are not allowed in C#.

If I return out of a try/finally in C#, does the code in the finally-clause run? – Yes. The code in the

finally always runs. If you return out of the try block, or even if you do a “goto” out of the try, the finally block always runs: using System;

class main { public static void Main() { try { Console.WriteLine(“In Try block”); return; } finally { Console.WriteLine(“In Finally block”); } } }

Both “In Try block” and “In Finally block” will be displayed. Whether the return is in the try block or after the try-finally block, performance is not affected either way. The compiler treats it as if the return were outside the try block anyway. If it’s a return More >

I was trying to use an “out int” parameter in one of my functions. How should I declare the variable that I am passing to it?

You should declare the variable as an int, but when you pass it in you must specify it as ‘out’, like the following: int i; foo(out i); where foo is declared as follows: [return-type] foo(out int o) { }