当你需要对某一字符或字符串重复输出时,可以参考下面2个方法。一个是new 字符串,另一个是使用Linq的Enumberable的Repeat方法来实现。

重复输出字符或字符串

 

class Bo
    {
        public void RepeatCharacter(char c, int times)
        {
            string output = new String(c, times);
            Console.WriteLine(output);
        }

        public void RepeatString(string str, int times)
        {
            var output = string.Concat(Enumerable.Repeat(str, times));
            Console.WriteLine(output);
        }
    }
Source Code

相关文章: