0000001
0000002
0000003
0000103
Here I will show two ways of doing so.
string sFiveZeros = new String('0', 5); Console.WriteLine(sFiveZeros); //Output: 00000 string sSevenStars = new String('*', 7); Console.WriteLine(sSevenStars); //Output: *******Now the other way is a mix of string.Concat() and System.Collections.ArrayList.Repeat() methods.
string sRepeated123 = string.Concat(System.Collections.ArrayList.Repeat("123", 5).ToArray()); Console.WriteLine(sRepeated123); //Output: 123123123123123 string sRepeatedAbc = string.Concat(System.Collections.ArrayList.Repeat("abc", 5).ToArray()); Console.WriteLine(sRepeatedAbc); //Output: abcabcabcabcabc
No comments:
Post a Comment