Requirements: In daily development, you may need to simply test some C# code or write a small demo, and it may be troublesome to create a new console application to execute each time.
First, open the "C# Interactive", run VS 2022 and select Continue without code, click "View" - > "Other Windows", as shown below:
Using the Environment.Version code, output the version of the current runtime.
For .NET Core 3.x and .NET 5+, the Environment.Version property returns the .NET runtime version number. For .NET Framework versions 4, 4.5, 4.5.1, and 4.5.2, the Environment.Version property returns a Version object with a string representation of 4.0.30319.xxxxx. For .NET Framework 4.6 and later and versions prior to .NET Core 3.0, it is in the form of 4.0.30319.42000. Reference:The hyperlink login is visible.
Check out the help on #help as follows:
Keyboard shortcuts: Enter evaluates the current commit if it shows complete. Otherwise, insert a new line. Ctrl-Enter evaluates the current commit within the current commit. Within the previous commit, append the previous commit to the current commit. Shift-Enter inserts a new line. Escape clears the current commit. Alt-UpArrow replaces the current commit with the previous commit. Alt-DownArrow replaces the current commit with the next commit (after it has previously navigated backwards). Ctrl-Alt-UpArrow replaces the current commit with the previous commit that starts with the same text. Ctrl-Alt-DownArrow replaces the current commit with the next commit that starts with the same text (after it has previously been navigated backwards). Ctrl-K, Ctrl-Enter paste the selected content at the end of the interactive buffer, placing the insertion point at the end of the input. Ctrl-E, Ctrl-Enter paste the selected content and execute it before any pending input in the interactive buffer. Ctrl-A selects the commit containing the cursor on the first press and selects all the text in the window the second time. REPL command: #cls, #clear clears the content in the editor window, keeping the history and execution context intact. #help Displays help for specified commands, or for all available commands and keybindings if not specified. #reset Reset the execution environment to its initial state and preserve history by selecting to switch the runtime of the host process. Script Instructions: #r Add metadata references to a given assembly and all of its dependencies, such as #r "myLib.dll". #load Load the specified script file and execute, e.g. #load "myScript.csx". useThe "Ctrl-Enter" key executes the code to be committed, and the "Alt-Up Arrow Symbol" selects to enter the historical code。
Run simple C# code to test:
Referencing other dll dependencies, if you want to serialize an object, you may need to use the Newtonsoft.Json library to load the dll with the #r command, the code is as follows:
At the same time, we can also save the code as a .csx file for easy execution next time, the file content is as follows:
The execution effect is as follows:
(End)
|