そのため、タイトルは少し誤解を招きやすいので、最初に整理します。
次のコードを検討してください。
public static ADescription CreateDescription(string file, string name, params string[] othername)
{
return new ADescription(file, name, othername.ToList<string>());
}
System.ArgumentNullException
これは、ユーザーが最後に意図的に null を入力した場合にスローされます。例:
ADescription.CreateDescription("file", "name", null); // example
これで、基本的にothername
リストを取得および設定するプロパティができました。私の懸念は、次のようなすべての段階で確認する必要があることです (プロパティ内、およびこのメソッド内):
if (othername == null){
// do nothing
}
else{
othername.ToList<string>; // for example
}
なぜなら、 には null が受け入れられるからですothername
。c# がこの機能をネイティブに提供する方法はありますか? ifothername
が null の場合、実際には ToList() を操作しません。