Reputation: 6383
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?
When hovering over a variable?
Upvotes: 4
Views: 315
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:
DebuggerDisplayAttribute
to change the way members of an object are shown (see this blog entry)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
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
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