C# 重载方法?为什么赢了';这个功能不起作用吗?

C# 重载方法?为什么赢了';这个功能不起作用吗?,c#,C#,有人可以编译这个(或者只是把代码粘贴到编译器中)并告诉我为什么要写一个记录(参考id、参考新闻目录、参考出版、参考价格、参考类型、参考标题、参考作者);说它有无效的参数 “与'as2.programs.write'one_record(int,int,int,double,string,string,string)'匹配的最佳重载方法具有一些无效参数。您在每个参数中都缺少ref关键字。” 如果在调用write\u one\u record(…)时试图使用ref关键字,那么在方法声明中也需要它。就

有人可以编译这个(或者只是把代码粘贴到编译器中)并告诉我为什么要写一个记录(参考id、参考新闻目录、参考出版、参考价格、参考类型、参考标题、参考作者);说它有无效的参数


“与'as2.programs.write'one_record(int,int,int,double,string,string,string)'匹配的最佳重载方法具有一些无效参数。

您在每个参数中都缺少
ref
关键字。”

如果在调用
write\u one\u record(…)
时试图使用
ref
关键字
,那么在方法声明中也需要它。就像在
void red\u one\u record(…)


如果您不打算使用
ref
,请将其从方法调用中删除。

在每个参数中都缺少
ref
关键字。

如果在调用
write\u one\u record(…)
时试图使用
ref
关键字
,那么在方法声明中也需要它。就像在
void red\u one\u record(…)


如果您不打算使用
ref
,请将其从方法调用中删除。

您将write\u one\u记录定义为

void write_one_record(ref int id, ref int newstock, ref int published, ref double price, ref string type, ref string title, ref string author)
->无
ref
参数

但你称之为

void write_one_record(int id, int newstock, int published, double price, string type, string title, string author)

->所有
ref
参数

您将write\u one\u记录定义为

void write_one_record(ref int id, ref int newstock, ref int published, ref double price, ref string type, ref string title, ref string author)
->无
ref
参数

但你称之为

void write_one_record(int id, int newstock, int published, double price, string type, string title, string author)

->所有
ref
parameters

因为
write\u one\u record
参数未声明为“ref”,但您将其作为“ref”传递。

因为
write\u one\u record
参数未声明为“ref”,但您将其作为“ref”传递“

write_one_记录
不包含任何
ref
参数,但在您对它的调用中它们都包含

鉴于您的方法使用参数的方式,应使用以下参数调用该方法:

writeinv.write_one_record(ref id, ref newstock, ref published, ref price, ref type, ref title, ref author);
而不是:

writeinv.write_one_record(id, newstock, published, price, type, title, author);

write\u one\u record
不包含任何
ref
参数,但在您对它的调用中它们都包含

鉴于您的方法使用参数的方式,应使用以下参数调用该方法:

writeinv.write_one_record(ref id, ref newstock, ref published, ref price, ref type, ref title, ref author);
而不是:

writeinv.write_one_record(id, newstock, published, price, type, title, author);
请读第一段

您还需要将ref关键字添加到方法参数中

writeinv.write_one_record(ref id, ref newstock, ref published, ref price, ref type, ref title, ref author);
请读第一段

您还需要将ref关键字添加到方法参数中

writeinv.write_one_record(ref id, ref newstock, ref published, ref price, ref type, ref title, ref author);


在调用方法时不要使用ref或直接在每个参数前添加“ref”。

在调用方法时不要使用ref或直接在每个参数前添加“ref”。

错误说明了什么?请减少代码示例。(也就是说,除去使错误出现所需的内容以外的所有内容。)您需要作废写入一条记录(ref int id,ref int newstock,….为什么要用ref修饰符传递参数?因为我不想用值传递它们?lol…如果我前面需要void,为什么它没有提示读取错误?错误是怎么说的?请减少您的代码示例。(也就是说,删除除出现错误所需的以外的所有内容。)你需要写一张空的记录(ref int id,ref int newstock,….你为什么用ref修饰符传递你的参数?因为我不想用值传递它们?lol…如果我前面需要void,为什么它没有提示读取错误?你在说什么?我已经读了和写了完全相同的内容。不,你没有,你没有在方法声明。你在说什么?我读过和写过完全相同的东西。不,你没有,你没有在方法声明中包含
ref
。谢谢。这解释得很好,我不知道我是怎么错过的。谢谢。@EugenRieck-非常感谢。谢谢。这解释得很好,我不知道我是怎么错过的“谢谢你,”尤金瑞克-非常感谢。