简体   繁体   English

如何将 int 值表示为 char/string (C#)?

[英]How can I represent an int value as a char/string (C#)?

How can I represent an int value as a char/string (c#)?如何将 int 值表示为 char/string (c#)? For example, if int = 3 and char = 'C', it should show me as a result CCC.例如,如果 int = 3 和 char = 'C',它应该向我显示结果 CCC。

(I am a beginner, please keep it simple D; and thx ) (我是初学者,请保持简单 D; 和 thx )

Not very clear title question but is that you want?不是很清楚的标题问题,但这是你想要的吗?

string str = new string('C', 3);

This string constructor creates a new string instance from a char repeated n times.此字符串构造函数从重复 n 次的 char 创建一个新的字符串实例。

You can write that too:你也可以这样写:

char letter = 'C';
int count = 3;

string result = new string(letter, count);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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