writeline是什么意思,writeline函数用法
得益于时代的进步,现在写c#可以直接使用顶级语句,非常简洁。
在.NET 5 及更早版本,控制台应用模板的helloworld代码是如下的样子的
using System;namespace MyApp // Note: actual namespace depends on the project name.{ internal class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.ReadKey(); //目前来说可有可无 } }}
以上代码段是微软官方文档的使用 C# 语言编写的控制台应用程序的示例。该程序使用了 System 命名空间中的 Console 类来在屏幕上输出消息 "Hello World"。程序的入口点是 Main 方法,该方法定义了程序的行为。最后一行代码 Console.ReadKey(); 用于防止程序在 Visual Studio .NET 启动时快速运行并关闭,等待用户按下任意键后才会退出。
是不是比较复杂,而现在.NET 6或更高只需要一行就行了
Console.WriteLine("Hello, World!");
在VS2022中简单的输入输出等
Console.WriteLine("Hello, World!"); //输出语句/*Ctrl+shift+/*///或者 ctrl+K ctrl+c 取消注释ctrl+K ctrl+uConsole.WriteLine("helloworld");Console.Write("helloworld");Console.Write("helloworld");//write不会换行Console.WriteLine("helloworld\nhahaha"); // \n 转义字符:换行Console.WriteLine("helloworld\thahaha"); // \t 制表符 //如果要输出\,用\\表示,\会把后面的转义Console.WriteLine("\""); // \"输出"Console.WriteLine("\\\""); // 打印出\"Console.WriteLine("我说: \" what is \\n ? \" "); // 打印出我说:"what is \n ?"
输出结果
之后是一些简单的加减法,体会各个输出的原因
int a = 3, b = 8;Console.WriteLine(a + b); //11Console.WriteLine("a + b"); //a+bConsole.WriteLine(a + "+" + b); //3+8Console.WriteLine("a+b" + a + b); //a+b38Console.WriteLine("a+b" + (a + b)); //a+b11Console.WriteLine((a + b) + "a+b"); //11a+bConsole.WriteLine("a" + (a + b) + "b"); //a11b
char a = 'c';int b = a;Console.WriteLine(a);Console.WriteLine(b); //accii码
a对应的ASCII码是99,所以输出99。
int a = 97;char b = (char)a;//强制类型转换Console.WriteLine(a);Console.WriteLine(b);
Console.WriteLine("c:\\a\\b\\c");Console.WriteLine();string str = @"www.baidu.com";Console.WriteLine(str);
用Readline做个收尾,readline记录了你输入的内容
本文地址:百科问答频道 https://www.neebe.cn/wenda/929339.html,易企推百科一个免费的知识分享平台,本站部分文章来网络分享,本着互联网分享的精神,如有涉及到您的权益,请联系我们删除,谢谢!