继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

重复输出字符或字符串

安卓软件程序开发入门学习
关注TA
已关注
手记 289
粉丝 49
获赞 282

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


测试:


 class Program    {        static void Main(string[] args)        {            Bo obj = new Bo();            obj.RepeatCharacter('$', 8);            Console.WriteLine();            obj.RepeatString("insus", 8);            Console.WriteLine();        }    }

Source Code

 

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP