Possible Duplicate:
When is it better to use String.Format vs string concatenation?
What is the best practices when using String.Format for C#. I always get confused here because it just seems way simpler to do operations like this
private string _ExecuteCommand(string cmd)
{
// Start the child process.
Process p = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
// Redirect the output stream of the child process.
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = String.Format("/C {0}", cmd); // prevents the command line from staying open after execution
//... you get the idea
}
Is there a particular advantage over using the String.Format vs just string concatenation? In other words, i could just do this instead...,
startInfo.Arguments = "/C " + cmd; // prevents the command line from staying open after execution
I would like to continue to persue quality code, but i do not know when its quality
to use String.Format. If anyone has any suggestions i would appreciate it.