如何解决“返回的参数过多"?问题 [英] How to solve "too many arguments to return" issue

查看:60
本文介绍了如何解决“返回的参数过多"?问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在编写的打印函数中,我试图基于switch语句的结果返回一个值;但是,我得到的错误太多了,无法返回.

In a print function I am writing, I am trying to return a value based on the result of a switch statement; however, I am getting the error too many arguments to return.

如果这个问题的答案很简单,请原谅我,但是函数有多少个参数可以返回一件事,这不应该吗?还是需要为每个参数返回一件事.

Forgive me if this question has a simple answer, but shouldn't it not matter how many arguments a function has and it can return just one thing? Or does it need to return one thing for each argument.

这是我的代码.我在返回行上收到错误(返回的参数过多).我该如何解决它,以便它返回在switch语句中设置的字符串?

Here is my code. I am getting an error on the return line ( Too many arguments to return ). How can I fix it so that it returns the string set in the switch statement?

package bay

func Print(DATA []TD, include string, exclude []string, str string) {
    result := NBC(DATA, include, exclude, str)
    var sentAnal string
    switch result {
    case 1:
        sentAnal = "Strongly Negative"
    case 2:
        sentAnal = "Very Negative"
    case 3:
        sentAnal = "Negative"
    case 4:
        sentAnal = "Little Negative"
    case 5:
        sentAnal = "Neurtral"
    case 6:
        sentAnal = "Little Positive"
    case 7:
        sentAnal = "Positive"
    case 8:
        sentAnal = "More Positive"
    case 9:
        sentAnal = "Very Positive"
    case 10:
        sentAnal = "Strongly Positive"
    default:
        sentAnal = "Unknown"
    }
    return sentAnal
}

推荐答案

您需要指定输入参数后返回的内容,这不是python.

You need to specify what you will return after specifying the input parameters, this is not python.

此:

func Print(DATA []TD, include string, exclude []string, str string) {

应该是:

func Print(DATA []TD, include string, exclude []string, str string) string {

推荐的内容:

http://golang.org/doc/effective_go.html#named-results

甚至所有有效执行

这篇关于如何解决“返回的参数过多"?问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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