我对 C# 很陌生——一天前才开始。我必须做一个简单的 C# 数据库,其中包含音乐专辑等。我遇到的问题是我无法调用我刚刚执行的方法,任何人都可以帮助我在 main 中包含这个方法吗?
void addnew()
{
int ID = currid;
string AlbNm;
string Art;
string RelDstring;
int RelD;
string TrAmnstring;
int TrAmn;
string Loc;
int Rat;
int ratswitch;
string ratswitchstring;
Console.Clear();
Console.WriteLine("Podaj nazwe albumu");
AlbNm = Console.ReadLine();
Console.WriteLine("Podaj nazwe wykonawcy");
Art = Console.ReadLine();
Console.WriteLine("Podaj rok wydania");
RelDstring = Console.ReadLine();
bool ifintreld = int.TryParse(RelDstring, out RelD);
bool correctyear = RelD < 2014 && RelD > 1900;
while (ifintreld == false)
{
Console.WriteLine("Podano bledny rok wydania, uzyj liczb calkowitych.");
RelDstring = Console.ReadLine();
}
RelD = Convert.ToInt32(RelDstring);
while (correctyear == false)
{
Console.WriteLine("Podano bledny rok wydania, uzyj daty z zakresu 1900-2014");
RelDstring = Console.ReadLine();
while (ifintreld == false)
{
Console.WriteLine("Podano bledny rok wydania, uzyj liczb calkowitych.");
RelDstring = Console.ReadLine();
}
RelD = Convert.ToInt32(RelDstring);
}
Console.WriteLine("Podaj ilosc utworow");
TrAmnstring = Console.ReadLine();
bool ifinttramn = int.TryParse(TrAmnstring, out TrAmn);
while (ifinttramn == false)
{
Console.WriteLine("Podano bledna liczbe utworow, uzyj liczb calkowitych.");
TrAmnstring = Console.ReadLine();
}
RelD = Convert.ToInt32(RelDstring);
Console.WriteLine("Podaj sciezke do pliku");
Loc = Console.ReadLine();
Console.WriteLine("Podaj ocene [1-5]");
ratswitchstring = Console.ReadLine();
bool ifintrat = int.TryParse(ratswitchstring, out ratswitch);
while (ifintrat == false)
{
Console.WriteLine("Podano bledna ocene, uzyj liczb calkowitych z zakresu 1-5.");
ratswitchstring = Console.ReadLine();
}
ratswitch = Convert.ToInt32(ratswitchstring);
while (ratswitch != 1 || ratswitch != 2 || ratswitch != 3 || ratswitch != 4 || ratswitch != 5)
{
Console.WriteLine("Podano bledna ocene, uzyj liczb calkowitych z zakresu 1-5.");
ratswitchstring = Console.ReadLine();
while (ifintrat == false)
{
Console.WriteLine("Podano bledna ocene, uzyj liczb calkowitych z zakresu 1-5.");
ratswitchstring = Console.ReadLine();
}
}
Rat = ratswitch;
}
VS 要求静态 main 中的非静态方法,但是对于 currid 和 currid++ 它不能是静态的(至少我这么认为;p)
谁能告诉我如何在我的控制台应用程序中运行此方法?
我假设这一切都在一个“程序”类中。要解决“静态”问题,只需创建该类的实例(或任何类)addnew
is in):
var p = new Program();
p.addnew();
It may努力使currid
改为静态;唯一的缺点是all的实例Program
会使用相同的currid
多变的。由于这只是一个学习练习,因此无论哪种方式都没有关系。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)