我有一个方法,由外部API调用,该API希望该方法具有这些特定参数。
public static bool DoSomething(
int x,
int y
) =>
true;
Roslyn 代码分析会报告一个 IDE0060 消息,如此处所述 (链接)。
具体消息如下:
Warning IDE0060 Remove unused parameter 'y' if it is not part of a shipped public API
我将 'x' 替换为 '_'
'y' 应该替换为什么?
__(双下划线)--编译器会抱怨没有使用 __(和 IDE0060 消息相同)
_(单下划线)--编译器会抱怨参数名 _ 是重复的(CS0100 错误)
_1 (下划线后面跟一个数字)--编译器会抱怨 _1 是未使用的参数(RCS1163 消息)
_
参数是不起作用的。但现在它可以工作了:https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/discards - Alex Fainshtein