第一天搞乱C#,不明白错误 [英] First day messing with C#, don't understand error

查看:85
本文介绍了第一天搞乱C#,不明白错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试编译一个代码,它会添加一系列变量,然后提供算术平均值并显示模数结果。我一直在粉碎我的脸,反对Main()错误,说CS1520方法必须有一个返回类型,并无法弄清楚我做错了什么。我的整个代码如下。我知道我现在的代码是文盲,所以请耐心等待我。



我尝试了什么:



So I'm trying to compile a code that adds up a series of variables, then provides the arithmetic mean and displays the modulo result. I've been smashing my face against a Main() error that says "CS1520 Method must have a return type" and can't figure out what I'm doing wrong. My entire code is below. I know I'm code illiterate at the moment, so please be patient with me.

What I have tried:

using System;
using System.Linq;

class Program
{
    static Main()
    {
        int number1, number2, number3;
        Console.Write("Enter an integer score");
        number1 = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter an integer score");
        number2 = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter an integer score");
        number3 = Convert.ToInt32(Console.ReadLine());

        int result = (number1 + number2 + number3) % 3;
        Console.WriteLine("The average of {0}, {1}, {2} is: {3}",
        number1, number2, number3, result);
    }
}

推荐答案

它必须是static void Main()。



如果没有返回,它仍然需要一个无效声明。
It needs to be static void Main().

If nothing returned its still needs a void declaration.


这篇关于第一天搞乱C#,不明白错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆