我一直在尝试学习 c#,但一直遇到问题。本质上,我正在尝试学习如何创建一个执行某些功能并被应用程序调用以执行该功能的类。
我最终遇到的错误(有很多其他人,但我试图尝试“修复”它们)是
is a 'type' but is used like a variable
到目前为止我整理的代码是;
namespace FirstConsoleApplication
{
class Program
{
public class checkConvertValue
{
public string formula1(string x)
{
Int32 isnumber = 0;
bool canConvert = Int32.TryParse(x, out isnumber);
string returnValue;
if (canConvert == true)
{
int val3 = Int32.Parse(x);
switch (val3)
{
case 50:
returnValue = "yep its 50";
break;
case 51:
returnValue = "hmmm.... its 51... what are you gonna do about that??";
break;
case 52:
returnValue = "lets not get sloppy now...";
break;
default:
returnValue = "nope, its definately something else";
break;
};
}
else
{
returnValue = "Thats not a number";
};
return returnValue;
}
}
static void Main(string[] args)
{
string num;
string result1;
do
{
Console.WriteLine("Guess what the value is, hint... its integer and between 1 and 100");
num = Console.ReadLine();
result1 = checkConvertValue(num);
Console.WriteLine(result1);
} while (result1 != "yep its 50");
Console.ReadLine();
}
}
}
有人可以让我知道我哪里出错了吗?