Please check the following c# code which retrieves area code from phone number
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;
I have the following code and I am trying with the phone number: +12015555777 which is formatted on e164 format which should give me code 201 NJ 'New Jersey' given the full areas list, but i get 'null' when checking areaCode, please advise me in any way possible to resolve this issue. I use the nuget of libphonenumber and phoneUs has the type PhoneNumber.