c# - C#: Char to string
问题描述
Why when I enter an input on each line = "a" "b" "c", I don't get an output "abc" but "294"? I get it that they get the number of each letter from the ascii table, but can someone explain me what to do to get "abc"?
using System;
namespace CharsToString
{
public class Program
{
public static void Main()
{
char firstInput = char.Parse(Console.ReadLine());
char secondInput = char.Parse(Console.ReadLine());
char thirdInput = char.Parse(Console.ReadLine());
Console.WriteLine(firstInput + secondInput + thirdInput);
}
}
}
解决方案
char is a integral type, you are adding values you need to call ToString
on each
Console.WriteLine(firstInput.ToString() + secondInput.ToString() + thirdInput.ToString());
Alternatively you could use a string builder, but given the example it seems like a premature optimization
推荐阅读
- c# - C# 跨项目程序集参考 - 何时重新编译
- python - Tensorflow 2.0 中的 tf.function 和 tf.while 循环
- python - tensorflow 如何在人脸识别上进行训练、验证和测试?
- python - 如何在没有目标值的数据集上使用决策树进行预测?
- python - 使用 PIL 库从 YCbCr 到 RGB 的色彩空间转换?
- ios - 使用 Swift 5.1 for iOS 中的 SwiftUI 使用 RadialGradient 填充动态大小的 Rectangle
- ruby-on-rails - Rails 5 yield 给出重复的内容
- python - 将python文件导入另一个python文件
- python - 使用 Python 和 Selenium 抓取 Instagram 上喜欢帖子的帐户的名称,但仅返回 11 个名称
- r - expss 包可以处理带有加权数据的多个答案问题吗?