{
class Program
{
static void Main(string[] args)
{
int id = 0, stock = 0, published = 0, newstock;
double price = 0.00;
string type = " ", title = " ", author = " ";
Program inventroy = new Program();
inventroy.read_one_record(ref id, ref stock, ref published, ref price, ref type, ref title, ref author);
Console.WriteLine("Update Number In Stock");
Console.WriteLine("=======================");
Console.Write("Item ID: ");
Console.WriteLine(id);
Console.Write("Item Type: ");
Console.WriteLine(type);
Console.Write("Price: ");
Console.WriteLine(price);
Console.Write("Number In Stock: ");
Console.WriteLine(stock);
Console.Write("Title: ");
Console.WriteLine(title);
Console.Write("Author/Artist: ");
Console.WriteLine(author);
Console.Write("Published: ");
Console.WriteLine(published);
Console.WriteLine("=======================");
Console.Write("Please Enter New Stock Number: ");
string line = Console.ReadLine();
newstock = int.Parse(line);
Program writeinv = new Program();
writeinv.write_one_record(ref id, ref newstock, ref published, ref price, ref type, ref title, ref author);
}
void read_one_record(ref int id, ref int stock, ref int published, ref double price, ref string type, ref string title, ref string author)
{
StreamReader myFile = File.OpenText("Inventory.dat");
id = int.Parse(myFile.ReadLine());
stock = int.Parse(myFile.ReadLine());
published = int.Parse(myFile.ReadLine());
price = double.Parse(myFile.ReadLine());
type = myFile.ReadLine();
title = myFile.ReadLine();
author = myFile.ReadLine();
myFile.Close();
}
void write_one_record(int id, int newstock, int published, double price, string type, string title, string author)
{
StreamWriter myFile = new StreamWriter(File.OpenWrite("Inventory.dat"));
myFile.WriteLine(id);
myFile.WriteLine(newstock);
myFile.WriteLine(published);
myFile.WriteLine(price);
myFile.WriteLine(type);
myFile.WriteLine(title);
myFile.WriteLine(author);
myFile.Close();
}
}
}
有人可以編譯這個(或者只是粘貼代碼到編譯器中)並告訴我爲什麼writeinv.write_one_record(ref id,ref newstock,ref published,ref price,ref type,ref title,ref author);說它有無效的論點?重載方法?爲什麼這個功能不起作用?
「爲 'as2.programs.write_one_record(INT,INT,INT,雙,字符串,字符串,字符串)' 最佳重載的方法匹配具有一些無效的參數。
錯誤說的是什麼? – SLaks 2012-02-07 01:25:50
請減少您的代碼示例。 (也就是刪除**所有**,除了使錯誤出現所需的東西外)。 – millimoose 2012-02-07 01:26:25
你需要void write_one_record(ref int id,ref int newstock,... – shenhengbin 2012-02-07 01:26:47