相关疑难解决方法(0)

CS0019运算符不能应用于'bool'和'int'类型的操作数

该计划是对作业的回应:

"创建一个名为Sum()accept 的方法,接受任意数量的整数参数并显示它们的总和.编写一个Main()方法,证明该Sum()方法在传递一个,三个,五个或十个整数数组时正常工作.将程序保存为UsingSum.cs."

来自Microsoft®VisualC#®2008,面向对象编程简介,3e,Joyce Farrell

我在"//步骤1:"部分中的代码是获取CS0019错误,该错误表明它不能应用于类型bool和的操作数int.

我非常怀疑这个代码还有其他问题,但它比我四小时前的情况有了很大改进......

using System;

public class UsingSum
{
    public static void Main()
    {
        Sum();
    }

    public static void Sum() 
    { 
       // Step 1: Addition of one, three, five
       bool q, r, s;
       int firstTotal, n, o, p;
       string k, l, m;

       Console.Write("Type the number 1: ");    
       k = Console.ReadLine();

       n = Convert.ToInt32(k);
       q = Convert.ToBoolean(k);

       Console.WriteLine();

       if (q == 1)
           Console.WriteLine("Input accepted."); …
Run Code Online (Sandbox Code Playgroud)

c# boolean operands

5
推荐指数
2
解决办法
7万
查看次数

标签 统计

boolean ×1

c# ×1

operands ×1