peoples said:W3bbo said:*snip*I got it you need () at the end of tostring !
C# is new to me. Why does it not do the () in the dot completion system ?
I got another question... In VB I use On Error Resume Next for errors, I need to write files and at times a file does not exist so i use the Error Handling to keep the code running. But I don't know how to do this in C# ???
Thanks for help.
For error handling, you're meant to use Try/Catch and Exceptions; The "On Error Do Something" in VB.NET is meant as a crutch for backwards compatibility with VB6 (i.e. never use it in new projects).
To see if a file exists or not:
try {
FileStream fs = new FileStream("path to file");
} catch(FileNotFoundException fex) {
}
...of course, you should never use exceptions for normal program flow, it's much better to test first:
try {
if( File.Exists("path to file") ) {
// do file operation here
} else {
// show error message to user
}
} catch(IOException ex) {
}
And as you're using C#, you might as well make use of the using() {} block to ensure your program doesn't shít itself if something bad happens in the file IO ops.