📜  c# string console readline array - C# (1)

📅  最后修改于: 2023-12-03 14:59:40.900000             🧑  作者: Mango

C# String Console ReadLine Array

Introduction

In C#, the string data type is used to represent a sequence of characters. It is one of the most commonly used data types in C#, and is used for various purposes such as storing user input, file contents, and more. The Console.ReadLine() method is used to read user input from the console, while arrays are used to store multiple values of the same data type.

String in C#

In C#, a string is a sequence of characters, and is surrounded by double quotes (""). For example:

string name = "John";

Strings can be concatenated using the + operator:

string firstName = "John";
string lastName = "Doe";
string fullName = firstName + " " + lastName;
Console.ReadLine() in C#

The Console.ReadLine() method is used to read user input from the console. It returns a string that represents the user input. For example:

Console.Write("Enter your name: ");
string name = Console.ReadLine();
Array in C#

An array is a collection of values of the same data type, and is declared using the square bracket notation ([]). For example:

string[] fruits = { "Apple", "Banana", "Orange" };

Values in an array can be accessed using their index:

string firstFruit = fruits[0];
string secondFruit = fruits[1];
Conclusion

In C#, the string data type, Console.ReadLine() method, and arrays are commonly used by developers. By understanding these concepts and their usage, programmers can better develop C# applications with user input and value storage.