方法实例:将一个字符串数组输出为|分割的形式,比如“梅西|卡卡|郑大世”
static void Main(string[] args) { string[] strArray = {"梅西","卡卡","C罗" }; Oper(strArray); Console.ReadKey(); } static void Oper(string[] strs) { string resoult = string.Empty; for (int i = 0; i < strs.Length-1; i++) { resoult += strs[i] + "|"; } resoult += strs[strs.Length - 1]; Console.WriteLine(resoult); }
用户只能输入0到100之间的数写一个方法,否则提示超出范围
static void Main(string[] args) { Say(); Console.ReadKey(); } static void Say() { while (true) { Console.WriteLine("请输入一个1-100之间的数字"); int num = Convert.ToInt32(Console.ReadLine()); if (num < 1 || num > 100) { Console.WriteLine("输入超出范围!请重新输入"); continue; } } }