The output will be : C:\MyFolderMyFile.txt, which is definitely what you really don’t want. If you are using this way to construct the file path then you may be ended up in doing some headbanging before you realize that you have missed a “\” at the end of the file path.
To avoid this type of silly mistakes there is a very good alternative available “Path.Combine”. If you are constructing your file path by this way then you don’t have to bother to remember to add that “\” at the end of each path fragments.
Here is the simple demo of it.
string filePath = “C:\MyFolder”;
string fileName = “MyFile.txt”;
string fullFIlePath = Path.Combine(filePath, fileName);
And this time the output will be : C:\MyFolder\MyFile.txt as expected.
N.B: To use Path.Combine you need to add the System.IO namespace.
Hope this will help you in avoiding a common coding mistake and make your code looks clean and simple.