C# Console.WriteLine Method

Soldato
Joined
2 May 2004
Posts
19,950
Hi,

I've got the following method:
Code:
        public void OutputSuccess(string Message)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(Message);
            Console.ResetColor()
        }

Is there any way I can use it like this?

Code:
OutputSuccess("Successfully downloaded {0}", File)

Obviously the above gives an error as it thinks I'm trying to pass File to the method as well.

I'm new to C# so forgive me if this is stupidly easy :D

Thanks.
 
Soldato
OP
Joined
2 May 2004
Posts
19,950
Figured out you can use String.Format like this:

Code:
OutputSuccess(String.Format(Successfully downloaded {0}", File))

Is there any way to avoid this? It'd be nice just to use OutputSuccess() rather than OutputSuccess(String.Format())

Thanks
 
Last edited:
Soldato
OP
Joined
2 May 2004
Posts
19,950
Sorted

Code:
        public void OutputSuccess(string Message, params object[] Args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(String.Format(Message, Args));
            Console.ResetColor();
        }
 
Back
Top Bottom