作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
一个小时前,我花了很多时间完成该项目,但是在正确保存该项目时遇到了问题,完全丢失了它。但是,我又做了一次,但是这次不起作用
我不确定这次我做错了什么...我想我做的完全一样,但是这次不行吗?
我遇到以下错误:
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;
}
最佳答案
将public string convertir(string str)
更改为public static string convertir(string str)
。对españolizar函数执行相同的操作。
关于c# - 我不明白我做了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9588724/
我是一名优秀的程序员,十分优秀!