在 c# 中向 char 添加一个 int 以将其 ascii 值向上移动(就像在 c++ 中一样)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10583215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 14:22:43 来源:igfitidea点击:
Add an int to a char in c# to move its ascii value up (just like in c++)
提问by Programer
In c++ this code would work:
在 C++ 中,这段代码可以工作:
char c='a';
int r=2;
c+=r;
This would do the same as c='c'.
How can I do the same in c#?
这与c='c'. 我如何在 c# 中做同样的事情?
回答by juergen d
Just cast it to charbefore adding it to c
在将其char添加到之前只需将其转换为c
char c='a';
int r=2;
c += (char) r;

