visual-studio c#中“生成方法存根”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2316549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:35:08  来源:igfitidea点击:

what does "generate method stub" mean in c#?

visual-studiocode-generation

提问by jello

I'm trying to call a function, and VS gives me an error (red underline), and i have the option to "generate method stub". What is this?

我正在尝试调用一个函数,VS 给了我一个错误(红色下划线),我可以选择“生成方法存根”。这是什么?

采纳答案by Adam Maras

It means that you're trying to call the function incorrectly; check to make sure you've spelled the method name correctly, and that you're passing it the proper number and types of arguments.

这意味着您试图错误地调用该函数;检查以确保方法名称拼写正确,并且传递给它的参数数量和类型正确。

回答by Stefanvds

The generate method stub will generate you a method which looks exactly like you've written it, with the same parameters. Probably are getting this error because you've misspelled the method or because it is in a different namespace.

generate 方法存根将为您生成一个与您编写的完全一样的方法,具有相同的参数。收到此错误可能是因为您拼错了该方法或因为它位于不同的命名空间中。

回答by Brian Rasmussen

It means you typed a wrong signature, so VS assumes this method doesn't exist. By using the shortcut VS can help you create the method as a stub (i.e. the signature, then you have to fill out the implementation).

这意味着您输入了错误的签名,因此 VS 假定此方法不存在。通过使用快捷方式 VS 可以帮助您将方法创建为存根(即签名,然后您必须填写实现)。

回答by jello

ahh I had

啊我有

method(button.Tag);

and a declaration of

和声明

void method(int tag)

so i fixed it with

所以我用

method(int.Parse(button.Tag.toString()));

i tried that before, but I forgot to put "toString", since I thought it was already an int... stupid little mistake. thx guys

我以前试过,但我忘了把“toString”,因为我认为它已经是一个int...愚蠢的小错误。谢谢伙计们