方法必须有返回类型?预计{错误? [英] Method must have a return type? Expected { errors?

查看:61
本文介绍了方法必须有返回类型?预计{错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class clsFootballpage Find(Int32 FootballTeamNo)

public class clsFootballpage Find(Int32 FootballTeamNo)

推荐答案

你应该学习一下C#语法的基础课程。在没有学习其基本语法和语法的情况下使用任何语言都是不合理的。在学习方面,快捷方式永远不是一个好主意。



您显示的代码由于以下几个原因无法编译:



- 你定义一个clsFootballpage而不给它一个正文(正文是在类的开始和结束括号之间)。至少必须声明一个空体。必须在本机构内声明类的字段,属性,方法,构造函数,运算符,事件,常量等。



(顺便说一句,在类名前加上 cls是你应该避免的东西;前缀没有任何有用的含义。相反,类名必须是自我记录的:人们应该通过阅读它的名字非常快速地知道类的基本功能;看看类和结构名称在.NET Framework中:流称为 Stream ,字符串是 String ;它们未声明为clsStream和clsString。)



- 你在这个类中定义一个方法,但你忘了说明它的返回类型。如果一个方法没有返回任何东西(VB中的Sub),它的返回类型是 void



所以你的代码片段是正确的,应该是这样的:

You should take a basic course about C# syntax. It is not sane to use any language without learning its basic syntax and grammar in the first place. Shortcuts are never a good idea when it comes to learning.

The code you show could not compile for several reasons:

- you define a clsFootballpage without giving it a body (the body is what is between the opening and closing brackets of the class). At least an empty body must be declared. Fields, properties, methods, constructors, operators, events, constants, etc. of the class must be declared inside this body.

(btw, prefixing class names with "cls" is something you should avoid ; the prefix does not carry any useful meaning. On the contrary, class names must be self documenting : one should know very quickly the basic functionality of the class by reading its name; look at class and structs names in the .NET Framework : a stream is called a Stream, a string is a String; they are not declared as clsStream nor clsString.)

- you define a method in this class, but you forget to state which is its return type. If a method does not return anything (a Sub in VB), its return type is void.

So your code snippet, to be correct, should look like:
public class FootballPage
{
   // This methods does something from a football team number
   public void Find(int footballTeamNo)
   {
      // TODO
   }
}





如果您想要更精确和有意义的答案,请通过更准确地描述您的问题来改进您的问题。如果你的英语不流利,你可以使用在线翻译。



Please improve your question by describing more precisely your issue, if you want a more precise and meaningful answer. You can use an online translator if you are not fluent in english.


好的..



1.你至少需要clsFootballpage后的开口支撑

2.找到需要装饰作为功能...



Okay..

1. You need at least an opening brace after clsFootballpage
2. Find needs a decoration as a function...

public class clsFootballpage {
    public static clsFootballpage Find(Int32 FootballTeamNo)
    { 
        /// Some Useful Code
    }
}


这篇关于方法必须有返回类型?预计{错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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