【发布时间】:2011-03-12 21:20:39
【问题描述】:
这是处理 c# switch 语句的适当方法还是仍然需要显式中断? reference
public static string ToRegistryString(AliceKey.AliceKeyPaths aliceKeyPath)
{
switch (aliceKeyPath)
{
case AliceKey.AliceKeyPaths.NET_CLR_DATA:
return @"\.NET CLR Data\";
case AliceKey.AliceKeyPaths.NET_CLR_NETWORKING:
return @"\.NET CLR Networking\";
case AliceKey.AliceKeyPaths.NET_DATA_PROVIDER_MSSQL:
return @"\.NET Data Provider for SqlServer\";
case AliceKey.AliceKeyPaths.NET_DATA_PROVIDER_ORACLE:
return @"\.NET Data Provider for Oracle\";
}
return new string(new char[0]);
}
【问题讨论】:
-
而不是把“return new string(new char[0]);”在 switch 语句之外,您还可以使用“默认值:返回新字符串(新字符 [0]);”在所有其他案件之后。这将是使用 Switch 语句的一种更简洁的方式。
标签: c# case switch-statement