IOException and +18 overloads with console.writeline

Associate
Joined
13 Jan 2012
Posts
2,340
Location
United Kingdom
Hey guys, this might be a stupid question. but i have noticed on my laptop (using visual studio) i get an IOException and +18 overloads with just a console.writeline. i noticed this when i was creating a program and it kept crashing.

I then opened a new project and did only Console.WriteLine("text"); but it showed as an IOException with +17 overloads. Is this normal or is something wrong?
 
Are you saying that you actually get an IOException when running your program? Or is it just that the VS tooltip indicates that it could throw an IOException? (The MSDN documentation says it can...)

Are the overloads not just indicating that you can do:

Console.WriteLine() - i.e. Just an empty line
Console.WriteLine("string") - string
Console.WriteLine(1024) - int
Console.WriteLine(true) - bool
Console.WriteLine('c') - char
Console.WriteLine(1.01M) - decimal

And so on for the other types it supports?
 
Sounds like john_s is correct. This is what I see in visual studio when I hover over the WriteLine method:
53lsD19.png
The 18 overloads are all the different ways you can use that method - there's 18 different combinations of objects you can put in the brackets.
The exceptions part is a list of all the possible exceptions that this method could throw. It just happens that in this case there is only 1, "System.IO.IOException". If you look at another method, Console.ReadLine for example, there are 3 different exceptions which could be thrown by this method.
It allows you to handle the different errors in different ways.
 
I figured out what the problem for my crashing was and it was unrelated. (turned out i was trying to print out the contents of a list that didn't exist!). Thanks for letting me know about the overloads etc :), i just never noticed that before.
 
Back
Top Bottom