What does console mean in C#
Console in C# means console. Console is a class that encapsulates some basic operations of the console, such as [Console.Write], which means writing a string directly to the console.
C#'s Console
Console.Write means writing characters directly to the console String, no newline is performed, and the previous characters can be continued to be written.
Console.WriteLine means writing a string to the console and then wrapping it.
Console.Read means reading a string from the console without line breaks.
Console.ReadLine means to wrap the string after reading it from the console.
Console.ReadKey Gets the next character or function key pressed by the user. The pressed key is displayed in the console window.
Console.Beep Plays a beep through the console speaker.
Console.Clear clears the console buffer and the display information of the corresponding console window.
Output to console
Output to console means outputting data to the console and displaying it. The .Net framework provides the console class to implement this task. The output method is as follows:
Console.WriteLine();
Console.Write() ;
Console.WriteLine(output value);
Console.Write(output value);
Console.WriteLine("Output format string", variable list);
Console.Write("Output format string", variable list);
Console.WriteLine("This is {0}, this is {1} and {2}",strName[0],strName[1],strName [2],strName3]);
This method contains two parameters: "format string" and variable list. "This is {0}, this is {1} and {2}" This is the format string. {0}, {1}, {2} are called placeholders, representing the variable table arranged in sequence, and 0 corresponds to the variable The first variable in the list, 1, corresponds to the second variable in the variable list, and so on to complete the output.
Input from the console
Input from the console means inputting data from the console to the program.
Input method provided by the Console class:
Console.ReadLine();
This code returns a string type data, which can be directly assigned to a string variable , such as:
string strname=Console.ReadLine();
Sometimes you need to input numbers from the console, and you need to use the content introduced earlier, data conversion, such as:
int num=int.Parse(Console.ReadLine()); int num=Convert.ToInt32(Console.ReadLine());
The above two sentences of code have the same effect, you can use it according to your own habits Choose any one.
Note:
The input results of Console.ReadLine() and Console.Read() are completely different and cannot be mixed.
Console.Read(), The return value is the ASCII code of the first character
Console.ReadLine(), The return value is a string.
That is to say, the read method can only read the first character, while ReadLine can read multiple characters and read in new lines
Console.ReadKey() Function:
read is read from the console, key means pressing the keyboard, so the combination means to get the user to press the function key and display it in the window. The previous code is used to pause the window. Function, in debugging mode, the window will only close after pressing any key
.
Simple case:
using System; using System.Collections.Generic; using System.Linq;using System.Text; using System.Threading.Tasks;namespace ConsoleTest { class Program { static void Main(string[] args) { Console.WriteLine("输入用户名和ID"); string name = Console.ReadLine(); int id = int.Parse(Console.ReadLine()); Console.WriteLine("User Name is {0} \nThe id is {1}",name, id); Console.ReadKey(); } }
The above is the detailed content of What does console mean in C#. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Guide to Active Directory with C#. Here we discuss the introduction and how Active Directory works in C# along with the syntax and example.

Guide to Random Number Generator in C#. Here we discuss how Random Number Generator work, concept of pseudo-random and secure numbers.

Guide to C# Data Grid View. Here we discuss the examples of how a data grid view can be loaded and exported from the SQL database or an excel file.

Guide to Factorial in C#. Here we discuss the introduction to factorial in c# along with different examples and code implementation.

The difference between multithreading and asynchronous is that multithreading executes multiple threads at the same time, while asynchronously performs operations without blocking the current thread. Multithreading is used for compute-intensive tasks, while asynchronously is used for user interaction. The advantage of multi-threading is to improve computing performance, while the advantage of asynchronous is to not block UI threads. Choosing multithreading or asynchronous depends on the nature of the task: Computation-intensive tasks use multithreading, tasks that interact with external resources and need to keep UI responsiveness use asynchronous.

Guide to Patterns in C#. Here we discuss the introduction and top 3 types of Patterns in C# along with its examples and code implementation.

Guide to Prime Numbers in C#. Here we discuss the introduction and examples of prime numbers in c# along with code implementation.

The history and evolution of C# and C are unique, and the future prospects are also different. 1.C was invented by BjarneStroustrup in 1983 to introduce object-oriented programming into the C language. Its evolution process includes multiple standardizations, such as C 11 introducing auto keywords and lambda expressions, C 20 introducing concepts and coroutines, and will focus on performance and system-level programming in the future. 2.C# was released by Microsoft in 2000. Combining the advantages of C and Java, its evolution focuses on simplicity and productivity. For example, C#2.0 introduced generics and C#5.0 introduced asynchronous programming, which will focus on developers' productivity and cloud computing in the future.
