码迷,mamicode.com
首页 > 编程语言 > 详细

c++ Hello World

时间:2015-03-16 20:52:54      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

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

运行结果

技术分享

c++ Hello World

标签:

原文地址:http://www.cnblogs.com/Durandal/p/4342586.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!