Tre*_*ent 4 c# nullable list out
这可能吗?
private void Test(out List<ExampleClass>? ExClass)
{
}
Run Code Online (Sandbox Code Playgroud)
可以为空的List <>也是一个out参数?
正如Anton所说,你不需要使用Nullable<T>- 但它肯定是一个out参数:
private void Test(out List<ExampleClass> foo)
Run Code Online (Sandbox Code Playgroud)
这是可能你混淆一个可空List<T>用List<T?>这将是有效的值类型...例如,你可以使用:
private void Test(out List<Guid?> foo)
Run Code Online (Sandbox Code Playgroud)
这将是一个out参数,它是一个可以为空的guid列表.
另一方面,out在void方法中使用参数通常并不好- 您通常应该将其用作返回类型.