首页 > 解决方案 > 为什么 Console.WriteLine() 不能同时打印一个字符串和一个 int

问题描述

Console.WriteLine()我在 C# 中有一个问题。它只是不显示stringint变量一起。

它只显示了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();

        }

    }
}

标签: c#

解决方案


您忘记为该总和计算提供占位符

Console.WriteLine("Here there are {0}",a+b);

推荐阅读