我正在从 xml 文件中读取数据并具有以下 switch 语句
switch (localVariable)
{
case "myStringVariable":
myClass.myStringVariable= subReader.ReadElementContentAsString();
break;
case "myOtherStringVariable":
myClass.myOtherStringVariable= subReader.ReadElementContentAsString();
break;
case "myBoolVariable":
myClass.myBoolVariable= subReader.ReadElementContentAsBool();
break;
我想将其优化为类似
switch (localVariable)
{
case "myStringVariable":
case "myOtherStringVariable":
myClass.localVariable= subReader.ReadElementContentAsString();
break;
case "myBoolVariable":
myClass.localVariable= subReader.ReadElementContentAsBool();
break;