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();
        }
    }
}
运行结果

 
                    
                     
                    
                 
                    
                 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号