当你需要对某一字符或字符串重复输出时,可以参考下面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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2021-08-14
  • 2022-03-08
  • 2022-01-06
  • 2022-12-23
猜你喜欢
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案