user276648
user276648

Reputation: 6383

How to display 1000 separator in C# Visual Studio debugger

When working with big numbers, especially long, it's a must to display them with 1000 separators.

Is there a way to display those separators?

Inside the watch window?

Watch window example

When hovering over a variable?

Hovering example

Upvotes: 4

Views: 315

Answers (3)

user276648
user276648

Reputation: 6383

As noted in the other answers, it's not directly possible. So until the feature request lands in Visual Studio, you need to manually do it. So to sum up, you can:

  • use DebuggerDisplayAttribute to change the way members of an object are shown (see this blog entry)
  • add a new variable with the string representation in your code (this is quite dirty as you'll want to remove it once you're done debugging)
  • format the data in the Watch window (so your first need to add your data in the watch window, and it won't work when you hover over your data). Eg
// For a long variable
myLong.ToString("N0")
// For a long array variable (that might slow VSNet down if you have tons of rows)
myLongArray.Select(l => l.ToString("N0"))

Upvotes: 1

Venkataraman R
Venkataraman R

Reputation: 12969

I would suggest you to create a new array(stringNumbers), which is having the thousand separator and use it in the watch window for your debugging purpose. After you are done with debugging, you can remove this array.

int[] numbers = { 100000, 300000 };
string[] stringNumbers = numbers.Select(n => n.ToString("N")).ToArray();

You can watch stringNumbers here in the watch window.

Upvotes: 1

John Lord
John Lord

Reputation: 2185

it's technically possible but not straightforward. Your easiest way would be to create a 2nd formatted variable and watch that instead.

The only way i know of to do this in the watch window is you can actually "watch" an expression by typing it in the watch window as an edit to the variable. The expression would append a formatted toString. This doesn't seem to work with arrays though.

Say however you had a variable "total". your watch would say total and you would double click on it and edit it to say total.ToString("C");

I hope this helps.

Upvotes: 4

Related Questions