码迷,mamicode.com
首页 > Windows程序 > 详细

c#控制台用数字6和9显示“I ? YOU”

时间:2015-05-21 14:12:25      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:控制台

利用数字6和9,只高亮9,显示出“I ? YOU”,效果如图:

技术分享


代码如下:

方法一:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

    class Program
    {
        private static string str = @"99669999996669999996699666699666999966699666699 
99699999999699999999699666699669966996699666699 
99669999999999999996699666699699666699699666699 
99666699999999999966666999966699666699699666699 
99666666999999996666666699666699666699699666699 
99666666669999666666666699666669966996699666699 
99666666666996666666666699666666999966669999996 ";

        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("请输入你的姓名并回车");
            string input = Console.ReadLine();
            bool istrue = false;

            if (input == "XXX")
            {
                foreach (char c in str)
                {
                    if (c == '6')
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    Console.Write(c);
                }
                Console.WriteLine();
                Console.ReadKey();
            }

            else
            {
                Console.WriteLine("您输入有误!");
            }
        }
    }
}


方法二:

  static void WriteString(String s)
        {
            var orginColor = Console.ForegroundColor;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i].Equals('6'))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                else
                {
                    Console.ForegroundColor = orginColor;
                    Console.ForegroundColor = ConsoleColor.Blue;
                }
                Console.Write(s[i]);
            }
            Console.WriteLine(); 
            Console.ReadKey();
        }
        static void Main()
        {
            WriteString(@"99669999996669999996699666699666999966699666699 
99699999999699999999699666699669966996699666699 
99669999999999999996699666699699666699699666699 
99666699999999999966666999966699666699699666699 
99666666999999996666666699666699666699699666699 
99666666669999666666666699666669966996699666699 
99666666666996666666666699666666999966669999996");
        }




c#控制台用数字6和9显示“I ? YOU”

标签:控制台

原文地址:http://blog.csdn.net/lisenyang/article/details/45890843

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