Console.WriteLine vs. Debug.WriteLine formatting

  • Thread starter Thread starter Zytan
  • Start date Start date
Z

Zytan

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?
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top