c# - 如何在 C# 中使用多个可选参数
问题描述
我有这样的方法:
public static void MyMethod(int a, String opt1 = null, byte[] opt2 = null)
{
//code
}
我想使用 opt1 调用一次 MyMeythod,然后使用 opt2 调用一次;
MyMethod(3,"param");
通话有效,但
MyMethod(3,new byte[]);
不编译
有没有办法做到这一点,或者我应该明确传递 opt1 null
解决方案
使用名称:
MyMethod(3, opt2: new byte[]);
推荐阅读
- c# - 尝试构建具有多个 where 条件的 linq 查询
- linux - perf 报告显示带有未解析内核符号的调用图
- rust - 为什么我的 Rust 程序总是进入 while 循环而从不退出
- javascript - 我想问一下 JS 中的 eventlistener 和 dom
- javascript - 在定义它的函数调用之外调用函数
- python - 从 2 个列表创建字典
- three.js - 如何使用@react-three/cannon 阻止相机通过 gltf 模型?
- java - 错误:不兼容的类型:字符串无法转换为 JSONObject url,(String) null,^
- python - 为什么我会丢失循环中的所有输出值,除了最后一个?
- css - 如何根据我的需要编辑引导文档中的链接模板?