{
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