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();
            }
        }
    }

    运行结果

  • 相关阅读:
    python pytest全局用例共用之conftest.py详解
    mybatis mapper文件中select标签参数汇总
    mybatis整合redis实现二级缓存(转载)
    代码智能---aiXcoder插件
    mybatis运行原理及源码流程分析
    linux关闭防火墙
    mysql 锁
    mysql 性能低下的分析
    针对msyql的like中 两边都不得不使用% 的场景分析
    mysql 相关文件路径、配置
  • 原文地址:https://www.cnblogs.com/Durandal/p/4342586.html
Copyright © 2011-2022 走看看