gpt4 book ai didi

c# - 我不明白我做了什么

转载 作者:行者123 更新时间:2023-12-02 11:07:12 25 4
gpt4 key购买 nike

一个小时前,我花了很多时间完成该项目,但是在正确保存该项目时遇到了问题,完全丢失了它。但是,我又做了一次,但是这次不起作用

我不确定这次我做错了什么...我想我做的完全一样,但是这次不行吗?

我遇到以下错误:

Error 1 An object reference is required for the non-static field, method, or property 'ConsoleApplication1.Program.convertir(string)' C:\Documents and Settings\modifiedForPersonalReasons\Program.cs 12 45 ConsoleApplication1



这是我的代码,我只打算放置错误行,但可能会丢失一些我们可能需要发现问题的信息:
    static void Main(string[] args)
{
Console.WriteLine("23.21 es " + convertir("23.21"));
Console.ReadLine();
}

public string convertir(string str)
{
string[] arr;
arr = str.Split('.');

string rtn = españolizar(arr[0], "peso");

if (arr.Length > 1)
{
rtn += " con " + españolizar(arr[1], "centavo");
}

return rtn;
}

public string españolizar(string str, string str2)
{
string[] list1 = { "cero", "un", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez", "once", "doce", "trece", "catorce", "quince" };
string[] list2 = { "nivelarindexes", "dieci", "veinti", "trei", "cuare", "cincue", "sese", "sete", "oche", "nove" };

int numero = int.Parse(str);
string strNumero = Convert.ToString(numero);

int primerDigito = int.Parse(Convert.ToString(strNumero[0]));
int segundoDigito = 0;

if (strNumero.Length > 1)
{
segundoDigito = int.Parse(Convert.ToString(strNumero[1]));
}

int cases = -1;

if (numero > -1 && numero < 16)
{
cases = 0;
}
else if (numero > 15 && numero < 30)
{
cases = 1;
}
else if (numero > 29 && numero < 100)
{
cases = 2;
}
else if (numero == 100)
{
cases = 3;
}

string rtn = "";

switch (cases)
{
case 0:
rtn = list1[numero] + " " + str2;
if (primerDigito != 1)
{
rtn += "s";
}
break;
case 1:
if (numero != 20)
{
rtn = list2[primerDigito] + list1[segundoDigito];
}
else
{
rtn = "veinte";
}
rtn += " " + str2 + "s";
break;
case 2:
rtn = list2[primerDigito] + "nta";
if (segundoDigito != 0)
{
rtn += " y " + list1[segundoDigito];
}
rtn += " " + str2 + "s";
break;
case 3:
rtn = "cien " + str2 + "s";
break;
case -1:
rtn = "número invalido";
break;
}

rtn = rtn.Replace("iun", "iún").Replace("idos", "idós").Replace("itres", "itrés").Replace("iseis", "iséis");

return rtn;
}

我可以发誓我什么都没改变:C

最佳答案

public string convertir(string str)更改为public static string convertir(string str)。对españolizar函数执行相同的操作。

关于c# - 我不明白我做了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9588724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com