Exactly the same way... only in C# you have to throw a ; at the end of the line, so:
Process.Start("calc.exe");
Worst case you'll have to add 'using System.Diagnostics;' to the top of the code file.
Remember though that VB.NET & C# target the exact same framework and virtually any call or class that can be used from one can be used nearly as easily in the other.
If I enter the following code: Process.Start("calc.exe") I have no problem launching a program but if I enter the following:
Process.Start("C:\Program Files\Internet Explorer\iExplorer.exe"); I get this error: "Unrecognized Escape Sequence."
This doesn't occur with Visual Basic. The C# help file explains why this occurs but the help file for "Process.Start" is not much help to me. If C# and Visual Basic use the same framework why the extra code just to launch an application from within a C# application?
Gotta love escape characters.
In the C/C++/C# world there are some characters that you cannot type out in code and have recognized like regular characters. To get around this one gets to deal with escape characters such as ‘\r’ (carriage return) ‘\n’ (new line) '\t' (tab) and so on.
The problem you are having is that it is interpreting your string to have a ‘\P’, ‘\I’ and a ‘\i’ escape characters because of the presence of your \ marks in between the quotes.
Two options exist for this... you can either double up on your \’s so that you use make clear that the string should contain the \ mark like so:
"C:\\Program Files\\Internet Explorer\\iExplorer.exe"
Otherwise you can prefix your string with the @ to tell C# to treat the following string literally and ignore any escape characters:
@"C:\Program Files\Internet Explorer\iExplorer.exe"
Take your pick, both work virtually the same way and result in the same value in the end.
Personally though I’m a bigger fan of the second one just cause it’s a heck of a lot easier to type out.
Once, again, Thanks! That worked.
Now 2 more questions:
1. In visual basic I type the following to display the date and time in a textbox.
txtClock.Text = DateTime.Now.ToLongDateString + " " + DateTime.Now.ToShortTimeString "
How do you accomplish the same in C#?
2. If you were recommending a beginners book in C# what would you recommed? I have a book from Microsoft Press but it's mostly worthless to someone like me who programs for "fun!"
Before I answer your questions I must suggest that if you have any more questions you should post them as new ones on the forum so that others are able to see them. That way you aren’t waiting for me to check on my previously commented on threads for help.
As to #1... just the same way, only you add a semicolon to the end of the line (which most lines of C# code have). One other change from your line is that you need to have the () characters at the end of the two method calls ala:
txtClock.Text = DateTime.Now.ToLongDateString() + "" + DateTime.Now.ToShortTimeString();
As for a book recommendation... the only beginners book I’ve ever taken a look at (aside from the POS that comes with Express) is Programming C# by Jesse Liberty and from what I have seen is a pretty decent book at teaching the fundamentals before jumping into the advanced stuff.