【发布时间】:2012-03-06 17:23:39
【问题描述】:
一个小时前,我花了很多时间完成了这个项目,但是我在正确保存它时遇到了问题并且完全丢失了它。但是,我又做了一次,但这次它不起作用
我不确定这次我做错了什么...我想我做的完全一样,但是这次不行?
我收到以下错误:
错误 1 非静态字段需要对象引用, 方法或属性 'ConsoleApplication1.Program.convertir(string)' C:\Documents 和 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
【问题讨论】:
标签: c# compiler-errors