无法转换为字符串 [英] Cannot convert to string

查看:81
本文介绍了无法转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 上了这个课

Hi Got this class

class Normale : IMathOperationDemo
    {
        decimal Alpha;
        decimal Beta;
        string mesatarja;
        string moda;
        string mesorja;
        string varianca;
        string Minimum;
        string Maximum;
        public string getMinimum(string Minimum)
    {
    Minimum.Value = Alpha.Value.ToString();
    return Minimum;
    }
        public string getMaximum(string Maximum)
        {
            Maximum.Value = Beta.Value.ToString();
            return Maximum;
        }
        public string GetMesatarja(string mesatarja)
        {
            mesatarja = (Alpha + Beta) / 2;
            return mesatarja.ToString
                                }
        public string GetMesorja(string mesorja)
        {
            mesorja = (Alpha + Beta) / 2;
            return mesorja.ToString;
        }
        public string GetModa(string moda)
        {
            moda = (Alpha + Beta) / 2;
            return moda.ToString;
        }
        public string GetVarianca(string varianca)
        {
            varianca = ((Beta-Alpha+1)*(Beta-Alpha+1)-1) / 12;
            return varianca.ToString;
        }
    }
}



出现错误:

字符串"不包含值"的定义,并且找不到找到接受字符串"类型的第一个参数的扩展方法值"(是否缺少using指令或程序集引用?

无法将类型十进制"隐式转换为字符串"

怎么了?

请帮忙

关于



Got errors :

''string'' does not contain a definition for ''Value'' and no extension method ''Value'' accepting a first argument of type ''string'' could be found (are you missing a using directive or an assembly reference?

Cannot implicitly convert type ''decimal'' to ''string''

What''s wrong?

Please help

Regards

推荐答案

public string GetMesatarja(string mesatarja)
{
    mesatarja =Convert.ToString((Alpha + Beta) / 2);
    return mesatarja;
}
public string GetMesorja(string mesorja)
{
    mesorja = Convert.ToString((Alpha + Beta) / 2);
    return mesorja;
}
public string GetModa(string moda)
{
    moda = Convert.ToString((Alpha + Beta) / 2);
    return moda;
}
public string GetVarianca(string varianca)
{
    varianca = Convert.ToString(((Beta-Alpha+1)*(Beta-Alpha+1)-1) / 12);
    return varianca;
}


整件事都是个坏主意.您正在尝试将所有计算转换为字符串.这没有意义.
同样,您当然对编程的目的仍然有很大的困惑.

您是否注意过MesatarjaGetMesorjaModa在不同的名称下具有相同的功能.您是否认为不同的参数名称可能会有所不同.

我觉得您误解了基本编程的基础知识.您可能不了解方法,参数,变量的作用.
我不知道该如何帮忙.您需要从编程基础课程开始,并做一些非常简单的练习,以了解其工作原理.

—SA
Whole thing is such a bad idea. You''re trying to convert all calculations to string. This is pointless.
Again you certainly still have a big confusion on what is programming for.

Did you pay attention that Mesatarja, GetMesorja and Moda is the same very function under different names. Do you think that different names of arguments may make any difference.

I feel you misunderstood the very basics of elementary programming. You probably don''t understand what a method, argument, variable do.
I don''t know how to help here. You need to start with elementary course on programming and do very simple exercises to see how it works.

—SA


您正在使用ToString而不是我注意到的ToString().
同样,在进行数学运算的步骤中,还应使用ToString()包装.
例如:
You are using ToString instead of ToString() I noticed.
Also in the steps where you are doing math, you should wrap with ToString().
For example:
public string GetVarianca(string varianca)
{
    varianca = ((Beta-Alpha+1)*(Beta-Alpha+1)-1) / 12;
    return varianca.ToString;
}


将不起作用,但这将:


will not work, but this will:

public string GetVarianca(string varianca)
{
    return (((Beta-Alpha+1)*(Beta-Alpha+1)-1) / 12).ToString(); 
}


因为您将数学函数的结果隐式转换为字符串"varianca"
您可能应该检查结果是否也不会引发异常.这只是让您入门.


Because you are implicitly converting the results of a math function to a string "varianca"
You should probably check that the result won''t throw an Exception, too. This is just to get you started.


这篇关于无法转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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