cs-script icon indicating copy to clipboard operation
cs-script copied to clipboard

using statement vs using declaration

Open johngardner58work opened this issue 1 year ago • 1 comments

Regarding the following `if (...) { // does NOT work in CS-Script but works in C# 8.0 and up. Note I was using .NET interactive using FileStream f = new FileStream(@"C:\users\jaredpar\using.md"); // statements }

// Is equivalent. This works in CS-Script if (...) { using (FileStream f = new FileStream(@"C:\users\jaredpar\using.md")) { // statements } }`

johngardner58work avatar Oct 02 '24 20:10 johngardner58work

This can be caused by the script engine using the older version of C# compiler which does not support that new way of declaring using. Though, if you are using the latest >NET SDK and CS-Script then it all is fine:

image

Update the script: image

And now check and execute it: image

If you want a faster compilation you can redirect the script engine to the csc.exe C# compiler: image

oleg-shilo avatar Oct 05 '24 02:10 oleg-shilo