![]() And it displays these values in the console window. It also retrieves the value of the DateTime.Now property, which contains the current local time, and assigns it to a variable named currentDate. It stores this string in a variable named name. This code displays a prompt in the console window and waits until the user enters a string followed by the Enter key. Replace the contents of the Main method in Program.cs, which is the line that calls Console.WriteLine, with the following code: Console.WriteLine("What is your name?") Ĭonsole.WriteLine($"Press any key to exit.") The program displays "Hello, World!" and ends.Įnhance the application to prompt the user for their name and display it along with the date and time. Run the following command in the Terminal: dotnet run But it's available in C# 10, and whether you use it in your programs is a matter of style preference. Most existing C# programs don't use top-level statements, so this tutorial doesn't use this new feature. In the latest version of C#, a new feature named top-level statements lets you omit the Program class and the Main method. Any command-line arguments supplied when the application is launched are available in the args array. Main is the application entry point, the method that's called automatically by the runtime when it launches the application. The code defines a class, Program, with a single method, Main, that takes a String array as an argument. NET Core at the Select environment prompt.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |