c# - 增量(x++)的打印结果返回原始值而不是递增一
问题描述
string text = "hello";
char[] ch = text.ToCharArray();
for (var x=0; x<text.Length; x++)
{
Console.Write(ch[x]++);
}
这是我当前的代码,它产生“hello”作为输出。
期望输出为“ifmmp”,因为每个字符都增加 1。
解决方案
你在同时写入和递增,先尝试递增,然后写入
for (x=0; x<text.Length; x++){
ch[x]++;
Console.Write(ch[x]);
}
推荐阅读
- javascript - 需要帮助我们使用 JavaScript 和 P5 使一个对象从另一个对象反弹
- jquery - Kendo Jquery Grid - 过滤逗号分隔值列
- javascript - 使用 Javascript 关闭侧边栏
- sql - 如何动态计算表值并从 SQL Server 中的参数中找到 Min 和 Max 目标
- neo4j - CYPHER/NEO4J:从模式理解列表结果中计算和删除重复项
- html - Carbon Design Systems UI Shell 组件在代码笔中不起作用
- python - 使用 GPU 训练 XGBoost 回归器时内核死机
- c - 无法调用函数而不陷入无限循环
- python - 上一个作业结束后如何添加调度程序作业
- python - 只能是存储在 pygame.sprite.Group 中的矩形对象