a quick c# question

Associate
Joined
16 Jun 2009
Posts
809
Ok just picking up c# and coming from a vb background. Im working through a book and noticed they have started prefixing strings with a @ character with no explanation.

Example: System.IO.StreamWriter objFile = new System.IO.StreamWriter(@"C:\Test.txt",true);

Why do they put a @ at the front? and are there any other chars that can go there?
 
Ok just picking up c# and coming from a vb background. Im working through a book and noticed they have started prefixing strings with a @ character with no explanation.

Example: System.IO.StreamWriter objFile = new System.IO.StreamWriter(@"C:\Test.txt",true);

Why do they put a @ at the front? and are there any other chars that can go there?

It means you don't have to delimit characters.

Eg

string driveLetter = "c:\\";
string driveLetter = @"c:\";

Are the same.

Works for white space too so you can do

String displayMessage = @"Something
something else something else something else something else something else something else something else something else something else something else something else

something else something else something else something else something else something else something else something else"

instead of:
String displayMessage = "Something \r\n \t something else something else something else something else something else something else something else something else something else something else something else\r\n \r\n something else something else something else something else something else something else something else something else"
 
Another big difference between VB and C# is the Select Case condition statement. This often catches out even experienced programmers while debugging.

C# implements a fall-thru Select Case function. This means that every Case block requires an explicit "break;" command to exit the whole Select Case. Without the "break;" the flow will fall down to the next case block in the list.

This functionality is by design and is very useful for situations.

VB doesn't offer a fall-thru function and breaks out of the Select after Case.

Hope this helps someone :)
 
Another big difference between VB and C# is the Select Case condition statement. This often catches out even experienced programmers while debugging.

C# implements a fall-thru Select Case function. This means that every Case block requires an explicit "break;" command to exit the whole Select Case. Without the "break;" the flow will fall down to the next case block in the list.

This functionality is by design and is very useful for situations.

VB doesn't offer a fall-thru function and breaks out of the Select after Case.

Hope this helps someone :)

Actually, unless the case block is empty, a missing break statement will trigger a compile-time error; C# only allows fall-through from empty blocks.
 
Back
Top Bottom