标签:控制台
利用数字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"); }
标签:控制台
原文地址:http://blog.csdn.net/lisenyang/article/details/45890843