How to declare variables and use statements in LINQPad?

Roy picture Roy · Oct 23, 2009 · Viewed 10.4k times · Source

Do you know how to declare variables in LINQPad in order to hold the query result and use it later in multiply queries?

Thanks!

Answer

Christian C. Salvadó picture Christian C. Salvadó · Oct 23, 2009

Just select C# or VB Statements, and you will be able to write variable declarations.

To view the content of your variables, you can use the Dump extension method available on all types:

var test = "Test String";
test.Dump(); // the content is shown in the output

Or you can use the Console.Write method.

linqpad

If you want to include method or class declarations within a LinqPad file, select C# or VB Program.