What I'm trying to do is to write a dedicated method for my StreamWriter instance, rather than make use of it at random points in the program. This localises the places where the class is called, as there are some bugs with the current way it's done.
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: stream is an instance of a TcpClient
With this I'm able to pass an array of variables to write, but I can't use the same method calls as with the existing method:
writer.WriteLine("hello {0} {1} {2}", variable1, variable2, variable 3);
writer.Flush();
It would be great if I was able to pass x number of variables to the method and for the loop to write each of them in this fashion, however optional parameters in .NET don't arrive till v4.0 which is still in beta.
Any ideas?