c# Hello World
2024-05-06 22:57:30
首先先尝试一下最基础的Hello World!
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleApplication2 { class Program { static void Main(string[] args) { System.Console.WriteLine("Hello World!"); System.Console.ReadLine(); } } }
Readline函数是因为我的控制台不会出现按任意键退出,所以手动补了一个Readline用来查看结果(防止控制台直接闪过去)
之后测试了关于颜色的 BackgroundColor和ForegroundColor
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleApplication2 { class Program { static void Main(string[] args) { System.Console.BackgroundColor = ConsoleColor.Green; System.Console.ForegroundColor = ConsoleColor.DarkRed; System.Console.WriteLine("Hello World!"); System.Console.ReadLine(); } } }
效果:
然后又试了一下另开一个类实现输出hello world!
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Class1 helloWorld = new Class1(); helloWorld.Hello(); System.Console.ReadLine(); } } }
Class1:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleApplication2 { class Class1 { public void Hello() { Console.WriteLine("Hello World From Class1!"); } } }
其中如果将Hello 函数改成static类型还可以不用实例化就可以调用
如下
main:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Class1.Hello(); System.Console.ReadLine(); } } }
Class1:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleApplication2 { class Class1 { public static void Hello() { Console.WriteLine("Hello World From Class1!"); } } }
尝试使用控制台的参数
设置内容:
代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleApplication2 { class Program { static void Main(string[] args) { System.Console.WriteLine(args[0] + " " + args[1]); System.Console.ReadLine(); } } }
运行结果
转载于:https://www.cnblogs.com/Durandal/p/4342586.html
最新文章
- 详细!看看顶级互联网公司都在研究的无服务器架构!
- asyncio 并发测试
- IcbcDaemon.exe是什么东西啊?
- char p[]与char *p的区别
- C语言获取某个分割符之前的内容
- 通过javascript在网页端生成zip压缩包并下载
- spring异常处理实例(登录例子)
- 真相:Java 开发者钟爱 Kotlin 的五个原因
- centos7.4装mysql_CentOS7.4用yum安装并配置MySQL5.7
- 【lizhi125】比Nero更好用的免费小巧的光盘刻录软件——ImgBurn(中文版)
- VS201x+Qt5开发,中文乱码解决
- Android多点触摸的判断
- 财务分析中三张财务报表计算公式
- python matplotlib cannot import name ‘artist‘ from ‘matplotlib‘
- 【HBUOJ】暴躁的阿生
- 芥川龙之介《烟草与魔鬼》
- 客服整理的聊天话术怎么导入到新电脑上面?
- React之antd按需加载
- 录屏功能怎么打开?检查一下你的电脑这些设置
- js实现淡入淡出轮播图
热门文章
- Windows防火墙添加80端口,解决apache无法访问的问题
- 解决html5中video标签无法播放mp4问题的办法
- 解决 sublime text3 运行python文件无法input的问题
- object references an unsaved transient instance - save the transient instance before flushing异常问题处理
- VS2010无法调试问题解决
- webpack-dev-server 设置反向代理解决跨域问题
- 解决 Command “python setup.py egg_info“ failed with error code 1 问题
- 收到“此应用程序正在从后台线程修改自动布局引擎”错误?
- 从另一个调用一个构造函数
- win11间歇性卡顿怎么办 windows11间歇性卡顿的解决方法