0

Basing on this question i would like to convert a users' nationality selected from a combobox to it's two letter country code. If a user selects "South Africa" as their country i need to convert it to "SA". I tried the code below and it throw a nullreference exception.

var regions = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(x => new RegionInfo(x.LCID));

var english_region = regions.FirstOrDefault(region => region.EnglishName == this.Nationality);

string code = english_region.TwoLetterISORegionName;
Community
  • 1
  • 1
capdiz
  • 101
  • 1
  • 10
  • You will need to debug your code. See the marked duplicate on how to do this. – nvoigt Feb 04 '15 at 09:29
  • Where exactly is the null reference exception thrown? Which variable is null? Use the debugger, set breakpoints, inspect variables, compare actual values against expected vaues. – DrKoch Feb 04 '15 at 09:30

0 Answers0