Tuesday, October 14, 2008

How do you generate documentation from the C# file commented properly with a command-line compiler?

Compile it with a /doc switch.



When you inherit a protected class-level variable, who is it available to?


Classes in the same namespace.



How can I get the ASCII code for a character in C#?

Casting the char to an int will give you the ASCII value: char c = 'f';

System.Console.WriteLine((int)c); or for a character in a string:

System.Console.WriteLine((int)s[3]);

The base class libraries also offer ways to do this

with the Convert class or Encoding classes if you need a particular encoding.



Is there an equivalent to the instanceof operator in Visual J++?

C# has the is operator:expr is type


My switch statement works differently! Why?

C# does not support an explicit fall through for case blocks.

The following code is not legal and will not compile in C#: switch(x)

{case 0:

// do something

case1:

// do something in common with

0default:

// do something in common with

//0, 1 and everything else

break;

}

To achieve the same effect in C#, the code must be modified as

shown below (notice how the control flows are explicit): class Test

{

public static void Main(){

int x = 3;

switch(x){

case 0:

// do something

goto case 1;case 1:

// do something in common with 0

goto default;

default:

// do something in common with 0, 1, and anything else

break;

}

}

}

0 comments: