What I'm trying to do is write a dedicated method for my StreamWriter instance, and not use it at random points in the program. This localizes the places where the class is called, as there are some errors with the current method.
Here is what I have at the moment:
public static void Write(string[] stringsToWrite) {
writer = new StreamWriter(stream);
writer.Write("hello");
foreach (string stringToWrite in stringsToWrite) {
writer.Write(" " + stringToWrite + " ");
}
writer.Flush();
}
Note: The stream is an instance of TcpClient.
With this, I can pass an array of variables for writing, but I cannot use the same method calls as the existing method:
writer.WriteLine("hello {0} {1} {2}", variable1, variable2, variable 3);
writer.Flush();
It would be great if I could pass x the number of variables to the method and write each of them in a way for the loop, however the optional parameters in .NET do not reach version 4.0, which is still in beta.
Any ideas?