简体   繁体   中英

What is the easiest way to build a string if i have the character and length

In C#, as inputs i have:

Letter: "A"
Length: 5

and i want to output:

"AAAAA"

Is there a more elegant way of doing this besides loop?

你可以使用字符串构造函数: new string('A', 5);

你可以只是重复String构造函数字符来创建String。

Console.WriteLine(new String('A', 5));

Yes:

String st = new String('A', 5);

See MSDN .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM