我对C#有疑问,请帮忙 [英] I have a doubt in C#, please help

查看:95
本文介绍了我对C#有疑问,请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个值为100的int变量aaa.100对应于ASCII中的"d".
我想将其分配给字符串变量abc,以便abc的值为"d"而不是100.

我该怎么办?

当我给出以下代码时,出现错误错误CS0029:无法将类型"int"隐式转换为字符串"

Hi,

I have an int variable aaa with the value 100. 100 corresponds to "d" in ASCII.
I want to assign this to a string variable abc so that abc has the value "d" and not 100.

How can I do this?

when I give the below code, I get the error error CS0029: Cannot implicitly convert type ''int'' to ''string''

int aaa = 100;
string abc = aaa;



但是当我执行



but when I do

abc = aaa.ToString()

时,我看到abc变为"100".但我希望abc成为"d".

我该怎么做?

, I see that abc becomes "100". But I want abc to become "d".

How can I do this?

推荐答案

你好,

请使用以下代码段
Hello,

Please use below code snippet
int aaa = 100;
char converted = Convert.ToChar(aaa);



请参考以下链接以获取更多详细信息:
http://social.msdn.microsoft.com/Forums/zh_CN/csharpgeneral/thread/c4a3ea1d-72f2-4482-954e-87b3d154c4fb [



Please refer below link for more detail :
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/c4a3ea1d-72f2-4482-954e-87b3d154c4fb[^]


Please let us know your feedback if any.


在下面使用以下代码:
Use this code below:
int aaa = 100;
char a = char(aaa); // Now a will contain d.


int
aaa = 100;
if (aaa = 100)
{
string abc = d;


}


这篇关于我对C#有疑问,请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆