我对C#很新鲜 - 刚开始一天前。我必须做一个简单的C#数据库,包括音乐专辑等。我得到的问题是,我不能调用我刚才做的一个方法,任何人都可以帮助我将这种方法包含在main中?C#在哪里添加一个方法
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喊静态主要非静态方法,但与currid和currid ++不能是静态的(至少我这么认为; P) 谁能告诉我如何经营我的控制台应用程序,这种方法吗?
这取决于此方法的位置以及您要从哪里调用它。签名是'void addNew()',它缺少访问修饰符(例如'public','private'等)。默认情况下,它们是'internal',它可能*够好,但你应该明确。你的电话代码在哪里? – Yuck
我明白你是新的,但这使得我的眼睛流血。看看[编码约定](http://msdn.microsoft.com/en-us/library/ff926074.aspx) – Jonesopolis
@Jonesy由于老鼠和老鼠开关?就我个人而言,我很感兴趣。 – Yuck