C#中Write()和WriteLine()的区别分析
作者:mdxy-dxy 时间:2023-11-04 21:04:23
Write()和WriteLine()都是System.Console提供的方法,两着主要用来将输出流由指定的输出装置(默认为屏幕)显示出来.
两着间的差异在
Console.WriteLine()方法是将要输出的字符串与换行控制字符一起输出,当次语句执行完毕时,光标会移到目前输出字符串的下一行.
至于Console.Write()方法,光标会停在输出字符串的最后一个字符后,不会移动到下一行。
Write()和WriteLine()区别
都是System.Console提供的方法
都是在屏幕显示
Write()显示完毕后不换行,WriteLine()换行
代码示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WriteLine和Write的区别
{
class Program
{
static void Main(string[] args)
{
//WriteLine输出后鼠标显示在下一行开头
//Write输出后不开始一个新行
System.Console.WriteLine("First WriteLine Line");
System.Console.WriteLine("Second WriteLine Line");
System.Console.Write("First Write Line");//First Write Line后面不开始新的一行,直接紧跟着输出Second Write Line
System.Console.Write("Second Write Line");
//passing parameters
System.Console.WriteLine("\nWriteLine:Parameter={0}", 123);
System.Console.Write("Write:Parameter={0}", 456);
System.Console.ReadKey();
}
}
}
输出
First WriteLine Line
Second WriteLine Line
First Write LineSecond Write Line
WriteLine:Parameter=123
Write:Parameter=456
标签:Write,WriteLine
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Spring cloud config 配置文件加密方式
2023-01-11 13:48:01
总结一次C++ 程序优化历程
2023-11-02 22:38:30
简单谈一谈Java中的Unsafe类
2021-11-21 00:13:40
![](https://img.aspxhome.com/file/2023/1/122301_0s.jpg)
如何将默认的maven仓库改为阿里的maven仓库
2022-09-30 14:16:31
![](https://img.aspxhome.com/file/2023/6/61526_0s.png)
Android中系统自带锁WalkLock与KeyguardLock用法实例详解
2023-11-26 01:50:49
C#中Foreach循环遍历的本质与枚举器详解
2022-08-04 05:31:12
![](https://img.aspxhome.com/file/2023/9/108699_0s.png)
最最常用的 100 个 Java类分享
2023-08-21 08:45:05
![](https://img.aspxhome.com/file/2023/3/103863_0s.jpg)
Android开发时尽管已root但是ddms还是没有data路径怎么办
2023-01-28 03:19:36
解决fastjson从1.1.41升级到1.2.28后报错问题详解
2021-12-30 21:55:35
Android仿网易新闻图片详情下滑隐藏效果示例代码
2023-05-31 02:14:03
![](https://img.aspxhome.com/file/2023/4/129034_0s.jpg)
android Watchdog 实现剖析
2022-07-12 06:39:21
![](https://img.aspxhome.com/file/2023/3/98683_0s.jpg)
C#程序员统计自己的代码行数
2021-10-18 05:37:37
![](https://img.aspxhome.com/file/2023/7/92987_0s.png)
maven中下载jar包源码和javadoc的命令介绍
2023-07-27 04:41:01
![](https://img.aspxhome.com/file/2023/3/61033_0s.png)
解决mybatis批量更新出现SQL报错问题
2023-11-29 04:12:47
![](https://img.aspxhome.com/file/2023/5/60155_0s.png)
Spring学习教程之AOP模块的概述
2022-06-04 00:17:13
![](https://img.aspxhome.com/file/2023/7/91747_0s.jpg)
java编写的文件管理器代码分享
2023-11-20 13:28:52
Java 通过API操作GraphQL
2021-12-24 03:21:49
ijkPlayer播放器的全自动编译脚本及最终编译包
2023-01-10 13:52:18
关于Java中BeanMap进行对象与Map的相互转换问题
2023-09-18 07:25:36
三行Android代码实现白天夜间模式流畅切换
2021-06-11 08:15:12
![](https://img.aspxhome.com/file/2023/7/139117_0s.gif)