1

As mentioned, I was wondering what is the difference between C# program with only top-level statements and no namespace nor main class and a csx script.

I'm using dotnet-script right now and it behaves the same for both .cs and .csx and I'm a bit confused.

Barstok
  • 49
  • 6
  • 1
    dotnet-script doesn't care about the filename extension, it will interactively execute both. The one place where it matters is when you want to run the script directly by clicking on the file in a file manager. Only a .csx file will automatically activate dotnet-script. – Hans Passant Dec 21 '22 at 20:26

1 Answers1

3

Because .csx is intended for scripting without a whole project involved, it has support for a few directives that aren't necessary when you're working in the context of a project.

For example, there an #r directive to load a DLL, and a #load directive to load another .csx file. See the example at https://learn.microsoft.com/en-us/archive/msdn-magazine/2016/january/essential-net-csharp-scripting.

In a C# project, all the C# files included in the project are automatically loaded, and there are directives in the project file to include nuget packages, dlls, etc.

StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315