views:

1045

answers:

10

There are times when I want to test new code from the forums or when I need to help my friends with specific C# problem. The problem is I don't want to create new "project" in Visual Studio each time just to code/run only this small code.

Java & Eclipse IDE comes up with "Scrapbook" feature which allows the execution of arbitrary Java expressions. What are the choices for C# programmers?

+3  A: 

I usually use csc directly from the command line

C:\Users\Greg>csc /o- /debug+ Test.cs

Greg Dean
+21  A: 

Snippet Compiler is great for this.

LINQPad is also good for testing out LINQ code.

P Daddy
+1 for Snippet Compiler
Greg Dean
The GUI looks promising. I will give it a try :D
m3rLinEz
It works great :)
m3rLinEz
I find LINQPad is good for all C# stuff, not just LINQ. I think it's misnamed
Will Dean
Saved me some time finding something usefull! I love snippet compiler!!
Peter
+1  A: 

This is something I've never liked about visual studio. One thing (and probally the only thing) I miss from VB6 was the ability to create a project, and run it without saving it or anything. Was great for just what you said.

I typically have at least one or two scrap projects of each type, (Console, Winforms, and Web), that I just rotate and use. This way I'm not always creating new projects.

JoshBerke
Express has this ;-p
Marc Gravell
+10  A: 

Here's what I do:

  • Go to Tools->Options->ProjectsAndSolutions, and disable "Save new projects when created".

  • Fire up a new VS, Ctrl-Shift-N to create a project, and use that.

  • Use C# Express to have something that launches more quickly and has less clutter, but still enough power to do most things.

Jay Bazuzi
Didn't know about that first option. +1 from me
Marc Gravell
+1 for the first option
JoshBerke
+3  A: 

Check also Snippy and the Snippy Addin for Reflector

CMS
+1  A: 

you could have a look into C# Scripting.

C# scripting

this is ment to allow you to build fast scripts without the use of the IDE.

HTH

bones

dbones
ok now i have seen the snipppy IDE, that looks like a better option :D
dbones
+1  A: 

I always keep a copy of Express Edition running; this can execute and debug projects without needing a proper file location (as long as you don't hit save). Does the job for me...

Marc Gravell
+2  A: 

I just use the scratch console application project that I've defined for just this purpose. I cut out whatever is in the main program and go to town. If I decide that I need to keep whatever I've prototyped, I create a new project and copy to it. Since I do this all the time, the project's always in my recent-projects list, too.

Robert Rossney
+1  A: 

I use a batch file (csc.bat):
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc %1 %2 %3 %4 %5 %6 %7 %8 %9

For vb.net I use this batch file(vbc.bat):
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc %1 %2 %3 %4 %5 %6 %7 /r:system.windows.forms.dll /r:system.data.dll /r:system.dll

For example: C:>csc testit.cs

Each will create a .net .exe file. This solution is not so good for Windows Forms applications, however.

+1  A: 

There's also the interactive C# shell, built on top of Mono:

http://mono-project.com/CsharpRepl

That's similar to what other languages have (for example, irb with Ruby)

Cory Foy