C#语句修改

2021-01-19 17:05发布

问题:

583行是C#8.0版本支持语法,这一句怎么修改可以兼容Unity,当前不兼容Unity.
[项目源码]https://github.com/twcclegg/libphonenumber-csharp/blob/master/csharp/PhoneNumbers/BuildMetadataFromXml.cs

回答1:

只能這樣吧

if (element.Attribute(LOCAL_ONLY) is { })
{
    var localLengths = element.Attribute(LOCAL_ONLY);
    //...
}


回答2:

var attr=element.Attribute(LOCAL_ONLY)
if (attr){
var v=localLengths.Value;
}



标签: c# 编程