C#中writeline的用法有哪几种
C#中writeline的用法有哪几种
在C#中,writeline方法有以下几种用法:
1. 将文本写入控制台:
```csharp
Console.WriteLine("Hello World");
```
2. 将变量的值写入控制台:
```csharp
int num = 5;
Console.WriteLine(num);
```
3. 格式化输出:
```csharp
string name = "John";
int age = 25;
Console.WriteLine("My name is {0} and I am {1} years old.", name, age);
```
4. 将文本写入文件:
```csharp
string filePath = "example.txt";
string text = "Hello World";
System.IO.File.WriteAllText(filePath, text);
```
5. 将文本追加到文件末尾:
```csharp
string filePath = "example.txt";
string text = "Hello World";
System.IO.File.AppendAllText(filePath, text);
```
这些是writeline方法的常见用法,但还有其他更多的用法可以根据具体需要进行使用。
文章来源:丸子建站
文章标题:C#中writeline的用法有哪几种
https://www.wanzijz.com/view/89181.html