In C++ I could do this, but I don't see how to do it in C#. Basically I want to use a format specifier in the Watch Window of my Visual Studio 2008 debugger to view only a slice or portion of an array. For example, if I have a 2D array like so:
int[,] myArray = new int[5,15]
I might only want to view the last 15 items in the list, so I would like to be able to put this into my watch window (or something similar):
myArray[5],15
Is there anything like this in Visual Studio?
The format specifiers supported by Visual Studio 2008 debugger is described here. Clearly, the C# debugger does not support the same specifiers as C++.
Building on #Omers answer, you could watch a "processed" version of the array using the following watch expression:
System.Linq.Enumerable.Reverse(System.Linq.Enumerable.Take(System.Linq.Enumerable.Reverse(x), 2)), results
Note: the results format specifier is useful when watching IEnumerable results when you're interested in the results only.
This doesn't directly answer your question, but if you have System.Core loaded, and a using System.Linq; in your scope, you could just evaluate myArray[5].Reverse().Take(5).Reverse() to get the last 5 values.
Check this out. This VS plugin increases the number of ways you can visualize data in debug mode.
http://karlshifflett.wordpress.com/mole-2010/
... there is a 2008 version as well
http://karlshifflett.wordpress.com/mole-2010/mole-for-visual-studio/
Related
I like linqpad, but often when I need it, I have some data in Visual studio that I need to do stuff with.
Therefore I would love to know if it is possible to copy some list of data into Linqpad, creating the necessary classes and inserting the same values into the list, so I have real data to work with
So I would debug and get something like this in a breakpoint:
I then want those 5 items in a list in linqpad that I can work with
Check out LINQBridgeVs, it's a VS Extension that allows you to launch LINQPad from the VS debugger copying a complex data type over to a new LINQPad snippet along with the debug time data.
After installing the extension, enable the solution you're debugging, click the magnifier dropdown for the complex type and click LINQBridgeVS Visualizer from the context menu.
A new snippet will be opened in LINQPad with the data structure and debug time data ready to go.
In certain cases typing an opening square bracket results in nothing at all. In particular when I want to type them on a variable in the right side of assignment expression:
arr[i] = arr
So I cant type, for example:
arr[i] = arr[9]
It has something to do with Resharper. However, turning of autocomplete and stuff doesn't seem to solve it. Anyone familiar with this problem?
I had the same issue the first time I insalled Resharper.
Look under Tools > Options > Environment > Keyboard to what is bound to Ctrl+Alt+^ (equals to AltGr+[ since I suppose you work on an AZERTY keyboard). Easiest way of doing is by just entering it as a new shortcut.
Remove or rebind the shortcut that comes up and you're good to go.
I had the almost same issue in Visual Studio Express 2012. I couldn't write theese -> } <-.
(Same problem as you, #hazard)
After reading #Bart's answer, I saw that Ctrl+Alt+0 was connected to something called "View.ViewCode". So I removed that shortcut and it worked.
What's weird though, is that I COULD write }s during the first few hours I used VS2012 after installing it.
In the olden times of .NET 1.1, I could use the SoapFormatter to find out exactly what was getting serialized when I copied an object into the clipboard.
Fast forward to 2010, and I tried to do the same trick. It turns out the SoapFormatter does not support generics. Is there an alternative way to find out exactly what binary objects are serialized into the clipboard?
For example lets say I have this class:
public class Foo
{
public List<Goo> Children;
}
If I send an instance of it to the clipboard, I would like to take a look at what is in the clipboard to see if it's children list was included or not.
Update: I was finally able to find the over copied field with the debugger. Visual Studio did it's job.
Not to be self-promoting here, but... ClipMate can do this. There's a hex view editor (turned off by default, enable in Tools | Options | Editor | Enable Binary View, the re-start the app) that can display any format. First, copy the data. Next, in ClipMate do and Edit | Capture Special. Turn on the formats that you're interested in, then ClipMate will copy those (and not just the simple formats that it would have already captured). Now you can see the hex dump in the preview/edit window.
EVEN THE TRIAL VERSION WILL DO THIS, and it's a full-featured, 30-days of actual use, eval period. I don't yet have a discount for SO users, but I'm thinking about it.
How do I get %LocalAppData% in C#?
If you would like to use an enumeration, try the following:
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Using this technique, you can also find all other Window's file paths (i.e Program Files, My Documents, etc).
Environment.GetEnvironmentVariable("LocalAppData") for C#, since Visual Studio isn't a language, unless you're looking to get that variable in one of the VS dialogs or something.
I don't think this exists, but I'll throw this out there anyway. Is it possible, while debugging, to search for a value in memory?
For example, if I have a string "uniqueString" cached somewhere in memory, but I don't know under which variable it's stored--can I do a search for it? As in, find out which variable(s) have "uniqueString" as their value?
This is for C# managed code.
windbg will let you do the search directly. 's' is the command you're looking for, here's a very good cheat sheet. sos extension lets you scan for string objects too in managed code though the s command should find them too (must use unicode aware search).
You have the same functionality in Visual Studio, available from the immediate window. Although, you'd have to manually somehow limit the address range to search in (see the syntax in the link).
(edit) BTW, you can easily create dumps from VS too: Debug->Save Dump As.