如何在c#中从libphonenumber中的电话号码中提取区号?

如何在c#中从libphonenumber中的电话号码中提取区号?,c#,libphonenumber,C#,Libphonenumber,请检查以下从电话号码中检索区号的c代码 AreaCodeMap map = new AreaCodeMap(); var areas = await _areas.GetAllAreasAsync(); SortedDictionary<int, string> sortedMapForUS = new SortedDictionary<int, string>(); foreach (var area in

请检查以下从电话号码中检索区号的c代码

        AreaCodeMap map = new AreaCodeMap();
        var areas = await _areas.GetAllAreasAsync();
        SortedDictionary<int, string> sortedMapForUS = new SortedDictionary<int, string>();
        foreach (var area in areas)
        {
            sortedMapForUS.Add(Int32.Parse(area.PhoneNoCode), area.AreaName);
        }
        map.readAreaCodeMap(sortedMapForUS);
        var areaCode = map.Lookup(phoneUS);
        if (areaCode == null)
        {
            throw new ApiException("No description for the area code was found", ConnectMeError.InvalidAreaCode);
        }  
        int areaCodeKey = sortedMapForUS.FirstOrDefault(x => x.Value == areaCode).Key;
AreaCodeMap=新的AreaCodeMap();
var areas=await_areas.getAllreasaSync();
SortedDictionary sortedMapForUS=新的SortedDictionary();
foreach(区域中的var区域)
{
sortedMapForUS.Add(Int32.Parse(area.PhoneNoCode)、area.AreaName);
}
地图。readAreaCodeMap(sortedMapForUS);
var areaCode=映射查找(phoneUS);
如果(区号==null)
{
抛出新的ApiException(“未找到区号说明”,ConnectMeError.InvalidAreaCode);
}  
int areaCodeKey=sortedMapForUS.FirstOrDefault(x=>x.Value==areaCode.Key;
我有以下代码,我正在尝试使用电话号码:+12015555777,其格式为e164格式,鉴于完整的区域列表,应为我提供代码201 NJ‘新泽西’,但我在检查区域代码时得到‘null’,请以任何可能的方式通知我解决此问题。 我使用libphonenumber的numget,phoneUs的类型为PhoneNumber