PC Review


Reply
Thread Tools Rate Thread

Console.WriteLine vs. Debug.WriteLine formatting

 
 
Zytan
Guest
Posts: n/a
 
      27th Feb 2007
This works:
Console.WriteLine("F: {0:F}", CurrTime);

But this doesn't:
Debug.WriteLine("F: {0:F}", CurrTime);

Any reason why?

Zytan

P.S. How does Debug.WriteLine() (and I assume Console.WriteLine(),
but maybe not) know to invoke ToString() for anything passed to it?
Is it because it demands a string, and the compiler looks for implicit
conversions, and since all classes are derived from Object which has
ToString(), meaning all classes have ToString(), the compiler always
has this to invoke?

 
Reply With Quote
 
 
 
 
Zytan
Guest
Posts: n/a
 
      27th Feb 2007
Let me change the code a little:

> This works:
> Console.WriteLine("{0:F}", DateTime.Now);
>
> But this doesn't:
> Debug.WriteLine("{0:F}", DateTime.Now);
>
> Any reason why?


By the way, I know that this will work:

string s = String.Format("{0:F}", DateTime.Now);
Debug.WriteLine(s);

and can be compressed into one line, if wanted.

Zytan

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
StreamWriter.WriteLine and ConsoleWriter.WriteLine Question tia sal22 ratullloch_delthis Microsoft C# .NET 2 6th Dec 2010 08:09 PM
Re: StreamWriter.WriteLine and ConsoleWriter.WriteLine Question tia sal22 ratullloch_delthis Microsoft C# .NET 0 4th Dec 2010 11:52 PM
Debug.WriteLine and Trace.WriteLine Bob S Microsoft C# .NET 2 23rd Oct 2007 03:35 AM
Debug.WriteLine and Trace.WriteLine from class. xxx@hotmail.com Microsoft ASP .NET 0 1st Sep 2005 02:24 PM
Formatting right justified percentages with Console.writeline() =?Utf-8?B?c2hhd25r?= Microsoft C# .NET 4 3rd May 2004 01:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:35 AM.