c# - 为什么 Console.WriteLine() 不能同时打印一个字符串和一个 int
问题描述
Console.WriteLine()
我在 C# 中有一个问题。它只是不显示string
和int
变量一起。
它只显示了string
而不是int
,它提到了一些关于字符串格式的东西,我不明白如何修复,而且以前没有发生在我身上。
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FirstStep
{
class Program11
{
static void Main(string[] args)
{
int a = 2;
int b = 4;
Console.WriteLine(" summ up to Digits ");
Console.WriteLine("Here there are",a+b);
Console.ReadKey();
}
}
}
解决方案
您忘记为该总和计算提供占位符
Console.WriteLine("Here there are {0}",a+b);
推荐阅读
- python - 通过读取python中的属性文件来获取值的关键基础?
- r - 异步进程阻塞 R Shiny 应用程序
- terminal - 出现错误后终端跳过输出
- excel - 通过文件是否存在定义的公式的自动计算
- python-3.x - 我正在使用二维列表,不确定如何在一个或多个特定行上找到最小值
- amazon-redshift - AWS 文档说合并连接可用于外部连接,但不能用于完全连接。这些是一样的吗?
- sql - SQL 循环遍历 800 万条记录并更新它们
- azure - 如何在 Azure 中使用 SSRS 将报告保存到目录
- go - 如何使用 RWMutex 和升级锁
- selenium - 未知选项:使用 selenium webdriver 时出现 -protocol 错误