简体   繁体   English

struct参数的默认值

[英]Default value for a struct parameter

How to initialize an optional paramerer for a structure type in C# ? 如何在C#中初始化结构类型的可选参数?
Is it possible in .NET 4.5? .NET 4.5中可能吗?

string Foo(string myArg, KeyValuePair<string, string> myOptionalArg = ???)
{
     // todo
}

Yes, you can initialize the optional argument to any compile time literal value that is of the appropriate type. 是的,您可以将可选参数初始化为适当类型的任何编译时文字值。 For KeyValuePair the only compile time literal that is of that type (at least in any version of C# that currently exists) will be default(KeyValuePair<string, string>) . 对于KeyValuePair ,唯一具有该类型的编译时文字(至少在当前存在的任何C#版本中)是default(KeyValuePair<string, string>)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM