views:

79

answers:

1

There are many times when I need to test a little snippet of .net code but rebuilding and publishing the entire project or writing a suite of unit tests just seems like overkill. For example, I am writing a regular expression right now and I want to see if it the pattern is matching on the right parts. I could go and find a million other utilities that do that sort of thing, but that is not exactly my point.

FireBug has an exact analogue to what I want - the FireBug console. There is a text box where the user can enter some JavaScript and FireBug will execute it on the spot and display the return value.

I would love to be able to enter something like (new Regex("b+")).Replace("abc", "x") and see the results without having to do all the overhead. Does VS have anything like this?

+2  A: 

In the Command Window (Ctrl+W, A) you can do simple expressions like

>? "foo".Replace("o", "O")
"fOO"

To test a snippet of any real size, I Alt+Tab over to LINQPad.

mmsmatt
thanks! the "?" is what i was missing. when I try that i get "The expression cannot be evaluated while in design mode." do you know a good reference for the capabilities of the command window? i suppose i can google it... :)
Jeff
@Jeff: Idk of a complete reference, but Microsoft Visual Studio Tips by Sara Ford introduced me to it.
mmsmatt
It seems that "?" is shorthand for Debug.Write, which only is accessible when in Debug Mode. That makes sense. Is there something that I can use outside of debug mode? At design time? Something like Console.Write?
Jeff
@Jeff: I did the above outside of the debugger, and I'll edit my answer to be more specific.
mmsmatt
thanks again! in my previous comment, i ran your query in vs 2010. now, i tested it in vs 2008 and it worked. it would seem that there have been changes with the command window in vs2010 that prevent this from being useful.ill check out linqpad. that seems like a promising tool! thanks so much!
Jeff