zoukankan      html  css  js  c++  java
  • c# Hello World

      首先先尝试一下最基础的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();
            }
        }
    }

    运行结果

  • 相关阅读:
    能飞英语学习软件学习实践
    英语学习方式总结与实践
    Hello World
    centos 7.6中搭建samba共享服务
    PHP漏洞全解(一)PHP网站的安全性问题
    MySQL查询语句练习题
    在PHP中使用CURL实现GET和POST请求的方法
    js数组的操作大全
    php四种基础算法:冒泡,选择,插入和快速排序法
    Linux查看端口使用状态及启动
  • 原文地址:https://www.cnblogs.com/Durandal/p/4342586.html
Copyright © 2011-2022 走看看