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

    运行结果

  • 相关阅读:
    你可能不知道的js -- 数据类型转换
    项目开发过程中使用工具的相关配置 -- git / svn / 谷歌跨域
    博客园个人博客页面主题
    keep-alive指定条件缓存的坑
    element的多文件上传
    谷歌应用商店扩展程序
    从郭建的遭遇(自称最惨的创业者)看‘程序员的人生观’(一)
    我深表遗憾
    入门学习三
    编程入门学习二
  • 原文地址:https://www.cnblogs.com/Durandal/p/4342586.html
Copyright © 2011-2022 走看看