如果参数值为null,则传递字符串

use*_*591 15 c#

我需要在函数中传递多个参数.我的要求是参数值不应该为NULL.如果参数为NULL,则传递"TBD".

例如

getBookInfo (string bookId, string bookName, string bookAuthor) 
//if any of the parameters is NULL, pass "TBD" string in parameter
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我可以使用三元运算符执行此操作,如果是,如何执行此操作?

Eni*_*ity 17

在调用方法时尝试这样做:

getBookInfo (bookId ?? "TBD", bookName ?? "TBD", bookAuthor ?? "TBD");
Run Code Online (Sandbox Code Playgroud)

?:当您可以使用空合并运算符时,三元运算符是一种浪费??.