If the title isn’t accurate enough, please feel free to change it to something more well named.
So i have a public static void:
public static void outputDictionaryContents(Dictionary<string, int> list)
{
foreach (KeyValuePair<string, int> pair in list)
{
Console.WriteLine("{0}, {1}", pair.Key, pair.Value);
}
}
and I am wanting to write out what it produce on a html file, it will output it fine on command prompt via:
outputDictionaryContents(sortedDict);
but when it comes to outputting it in my html with the following code:
tw.WriteLine("<td width\"480\">{0}</td>", outputDictionaryContents(sortedDict));
but I keep getting the following error:
The best overloaded method match for 'System.IO.TextWriter.WriteLine(string, object)' has some invalid arguments
Argument '#2' cannon convert 'void' expression to type 'object'
So i’m not completely sure in what the best way is to fix this problem.
Thanks in advance.
Your method doesn’t return a string – it writes to the console.
You could change it to return a string directly:
That being said, if you’re going to write this into an HTML output, you probably need to rethink what you want to write. Writing newline separated info directly into a table cell is not going to format correctly…
You are more likely going to, at a minimum, want some additional formatting, or provide a separate terminator (such as a
<br />instead of a newline)…