开发者

Standardized US States Array and Countries Array

Does anyone know of a nice, usable class th开发者_开发技巧at everyone on here could benefit from to use in populating the ComboBox controls on a form for the Country and State fields?

I hate having to reinvent the wheel every time, and someone has probably done a very nice piece of work somewhere.

Bonus points if the existing class can return a list of State options whenever the Country is selected!

I'm currently developing this for a Windows Form (non-web application), and this project can't pull from a website.


OK, so I made one.

I built it nice and generic, so anyone should be able to use it

There is a class at the bottom called US_States that is used as a container to store the State Name and State Abbreviation.

static class StateArray {

  static List<US_State> states;

  static StateArray() {
    states = new List<US_State>(50);
    states.Add(new US_State("AL", "Alabama"));
    states.Add(new US_State("AK", "Alaska"));
    states.Add(new US_State("AZ", "Arizona"));
    states.Add(new US_State("AR", "Arkansas"));
    states.Add(new US_State("CA", "California"));
    states.Add(new US_State("CO", "Colorado"));
    states.Add(new US_State("CT", "Connecticut"));
    states.Add(new US_State("DE", "Delaware"));
    states.Add(new US_State("DC", "District Of Columbia"));
    states.Add(new US_State("FL", "Florida"));
    states.Add(new US_State("GA", "Georgia"));
    states.Add(new US_State("HI", "Hawaii"));
    states.Add(new US_State("ID", "Idaho"));
    states.Add(new US_State("IL", "Illinois"));
    states.Add(new US_State("IN", "Indiana"));
    states.Add(new US_State("IA", "Iowa"));
    states.Add(new US_State("KS", "Kansas"));
    states.Add(new US_State("KY", "Kentucky"));
    states.Add(new US_State("LA", "Louisiana"));
    states.Add(new US_State("ME", "Maine"));
    states.Add(new US_State("MD", "Maryland"));
    states.Add(new US_State("MA", "Massachusetts"));
    states.Add(new US_State("MI", "Michigan"));
    states.Add(new US_State("MN", "Minnesota"));
    states.Add(new US_State("MS", "Mississippi"));
    states.Add(new US_State("MO", "Missouri"));
    states.Add(new US_State("MT", "Montana"));
    states.Add(new US_State("NE", "Nebraska"));
    states.Add(new US_State("NV", "Nevada"));
    states.Add(new US_State("NH", "New Hampshire"));
    states.Add(new US_State("NJ", "New Jersey"));
    states.Add(new US_State("NM", "New Mexico"));
    states.Add(new US_State("NY", "New York"));
    states.Add(new US_State("NC", "North Carolina"));
    states.Add(new US_State("ND", "North Dakota"));
    states.Add(new US_State("OH", "Ohio"));
    states.Add(new US_State("OK", "Oklahoma"));
    states.Add(new US_State("OR", "Oregon"));
    states.Add(new US_State("PA", "Pennsylvania"));
    states.Add(new US_State("RI", "Rhode Island"));
    states.Add(new US_State("SC", "South Carolina"));
    states.Add(new US_State("SD", "South Dakota"));
    states.Add(new US_State("TN", "Tennessee"));
    states.Add(new US_State("TX", "Texas"));
    states.Add(new US_State("UT", "Utah"));
    states.Add(new US_State("VT", "Vermont"));
    states.Add(new US_State("VA", "Virginia"));
    states.Add(new US_State("WA", "Washington"));
    states.Add(new US_State("WV", "West Virginia"));
    states.Add(new US_State("WI", "Wisconsin"));
    states.Add(new US_State("WY", "Wyoming"));
  }

  public static string[] Abbreviations() {
    List<string> abbrevList = new List<string>(states.Count);
    foreach (var state in states) {
      abbrevList.Add(state.Abbreviations);
    }
    return abbrevList.ToArray();
  }

  public static string[] Names() {
    List<string> nameList = new List<string>(states.Count);
    foreach (var state in states) {
      nameList.Add(state.Name);
    }
    return nameList.ToArray();
  }

  public static US_State[] States() {
    return states.ToArray();
  }

}

class US_State {

  public US_State() {
    Name = null;
    Abbreviations = null;
  }

  public US_State(string ab, string name) {
    Name = name;
    Abbreviations = ab;
  }

  public string Name { get; set; }

  public string Abbreviations { get; set; }

  public override string ToString() {
    return string.Format("{0} - {1}", Abbreviations, Name);
  }

}


Updated jp2codes example, and added Canada:

public static class States {
    public static List<State> los = new List<State> {
      //us
      new State("AL", "Alabama"),
      new State("AK", "Alaska"),
      new State("AZ", "Arizona"),
      new State("AR", "Arkansas"),
      new State("CA", "California"),
      new State("CO", "Colorado"),
      new State("CT", "Connecticut"),
      new State("DE", "Delaware"),
      new State("DC", "District Of Columbia"),
      new State("FL", "Florida"),
      new State("GA", "Georgia"),
      new State("HI", "Hawaii"),
      new State("ID", "Idaho"),
      new State("IL", "Illinois"),
      new State("IN", "Indiana"),
      new State("IA", "Iowa"),
      new State("KS", "Kansas"),
      new State("KY", "Kentucky"),
      new State("LA", "Louisiana"),
      new State("ME", "Maine"),
      new State("MD", "Maryland"),
      new State("MA", "Massachusetts"),
      new State("MI", "Michigan"),
      new State("MN", "Minnesota"),
      new State("MS", "Mississippi"),
      new State("MO", "Missouri"),
      new State("MT", "Montana"),
      new State("NE", "Nebraska"),
      new State("NV", "Nevada"),
      new State("NH", "New Hampshire"),
      new State("NJ", "New Jersey"),
      new State("NM", "New Mexico"),
      new State("NY", "New York"),
      new State("NC", "North Carolina"),
      new State("ND", "North Dakota"),
      new State("OH", "Ohio"),
      new State("OK", "Oklahoma"),
      new State("OR", "Oregon"),
      new State("PA", "Pennsylvania"),
      new State("RI", "Rhode Island"),
      new State("SC", "South Carolina"),
      new State("SD", "South Dakota"),
      new State("TN", "Tennessee"),
      new State("TX", "Texas"),
      new State("UT", "Utah"),
      new State("VT", "Vermont"),
      new State("VA", "Virginia"),
      new State("WA", "Washington"),
      new State("WV", "West Virginia"),
      new State("WI", "Wisconsin"),
      new State("WY", "Wyoming"),
      //canada
      new State("AB", "Alberta"),
      new State("BC", "British Columbia"),
      new State("MB", "Manitoba"),
      new State("NB", "New Brunswick"),
      new State("NL", "Newfoundland and Labrador"),
      new State("NS", "Nova Scotia"),
      new State("NT", "Northwest Territories"),
      new State("NU", "Nunavut"),
      new State("ON", "Ontario"),
      new State("PE", "Prince Edward Island"),
      new State("QC", "Quebec"),
      new State("SK", "Saskatchewan"),
      new State("YT", "Yukon"),
      };

    public static List<string> Abbreviations() {
      return los.Select(s => s.Abbreviation).ToList();
    }

    public static List<string> Names() {
      return los.Select(s => s.Name).ToList();
    }

    public static string GetName(string abbreviation) {
      return los.Where(s => s.Abbreviation.Equals(abbreviation, StringComparison.CurrentCultureIgnoreCase)).Select(s => s.Name).FirstOrDefault();
    }

    public static string GetAbbreviation(string name) {
      return los.Where(s => s.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)).Select(s => s.Abbreviation).FirstOrDefault();
    }

    public static List<State> ToList() {
      return los;
    }
  }

  public class State {
    public State(string ab, string name) {
      Name = name;
      Abbreviation = ab;
    }

    public string Name { get; set; }

    public string Abbreviation { get; set; }

    public override string ToString() {
      return string.Format("{0} - {1}", Abbreviation, Name);
    }
  }


public partial class State
{
    public string Name { get; set; }
    public string Abbreviations { get; set; }
}

    /// <summary>
    /// Return a static list of all U.S. states
    /// </summary>
    /// <returns></returns>
    public IEnumerable<State> ListOfStates()
    {
        var states = CreateStateList();
        return states.ToList();
    }

    private static IList<State> CreateStateList()
    {
        List<State> states = new List<State>();

        states.Add(new State() { Abbreviations = "AL", Name = "Alabama" });
        states.Add(new State() { Abbreviations = "AK", Name = "Alaska" });
        states.Add(new State() { Abbreviations = "AR", Name = "Arkansas" });
        states.Add(new State() { Abbreviations = "AZ", Name = "Arizona" });
        states.Add(new State() { Abbreviations = "CA", Name = "California" });
        states.Add(new State() { Abbreviations = "CO", Name = "Colorado" });
        states.Add(new State() { Abbreviations = "CT", Name = "Connecticut" });
        states.Add(new State() { Abbreviations = "DC", Name = "District of Columbia" });
        states.Add(new State() { Abbreviations = "DE", Name = "Delaware" });
        states.Add(new State() { Abbreviations = "FL", Name = "Florida" });
        states.Add(new State() { Abbreviations = "GA", Name = "Georgia" });
        states.Add(new State() { Abbreviations = "HI", Name = "Hawaii" });
        states.Add(new State() { Abbreviations = "ID", Name = "Idaho" });
        states.Add(new State() { Abbreviations = "IL", Name = "Illinois" });
        states.Add(new State() { Abbreviations = "IN", Name = "Indiana" });
        states.Add(new State() { Abbreviations = "IA", Name = "Iowa" });
        states.Add(new State() { Abbreviations = "KS", Name = "Kansas" });
        states.Add(new State() { Abbreviations = "KY", Name = "Kentucky" });
        states.Add(new State() { Abbreviations = "LA", Name = "Louisiana" });
        states.Add(new State() { Abbreviations = "ME", Name = "Maine" });
        states.Add(new State() { Abbreviations = "MD", Name = "Maryland" });
        states.Add(new State() { Abbreviations = "MA", Name = "Massachusetts" });
        states.Add(new State() { Abbreviations = "MI", Name = "Michigan" });
        states.Add(new State() { Abbreviations = "MN", Name = "Minnesota" });
        states.Add(new State() { Abbreviations = "MS", Name = "Mississippi" });
        states.Add(new State() { Abbreviations = "MO", Name = "Missouri" });
        states.Add(new State() { Abbreviations = "MT", Name = "Montana" });
        states.Add(new State() { Abbreviations = "NE", Name = "Nebraska" });
        states.Add(new State() { Abbreviations = "NH", Name = "New Hampshire" });
        states.Add(new State() { Abbreviations = "NJ", Name = "New Jersey" });
        states.Add(new State() { Abbreviations = "NM", Name = "New Mexico" });
        states.Add(new State() { Abbreviations = "NY", Name = "New York" });
        states.Add(new State() { Abbreviations = "NC", Name = "North Carolina" });
        states.Add(new State() { Abbreviations = "NV", Name = "Nevada" });
        states.Add(new State() { Abbreviations = "ND", Name = "North Dakota" });
        states.Add(new State() { Abbreviations = "OH", Name = "Ohio" });
        states.Add(new State() { Abbreviations = "OK", Name = "Oklahoma" });
        states.Add(new State() { Abbreviations = "OR", Name = "Oregon" });
        states.Add(new State() { Abbreviations = "PA", Name = "Pennsylvania" });
        states.Add(new State() { Abbreviations = "RI", Name = "Rhode Island" });
        states.Add(new State() { Abbreviations = "SC", Name = "South Carolina" });
        states.Add(new State() { Abbreviations = "SD", Name = "South Dakota" });
        states.Add(new State() { Abbreviations = "TN", Name = "Tennessee" });
        states.Add(new State() { Abbreviations = "TX", Name = "Texas" });
        states.Add(new State() { Abbreviations = "UT", Name = "Utah" });
        states.Add(new State() { Abbreviations = "VT", Name = "Vermont" });
        states.Add(new State() { Abbreviations = "VA", Name = "Virginia" });
        states.Add(new State() { Abbreviations = "WA", Name = "Washington" });
        states.Add(new State() { Abbreviations = "WV", Name = "West Virginia" });
        states.Add(new State() { Abbreviations = "WI", Name = "Wisconsin" });
        states.Add(new State() { Abbreviations = "WY", Name = "Wyoming" });
        return states.ToList();
    }

VB.NET

Public Shared Function CreateStateList() As IList(Of State)
        Dim states As New List(Of State)()
        states.Add(New State() With {.Abbreviation = "AL", .Name = "Alabama"})
        states.Add(New State() With {.Abbreviation = "AK", .Name = "Alaska"})
        states.Add(New State() With {.Abbreviation = "AR", .Name = "Arkansas"})
        states.Add(New State() With {.Abbreviation = "AZ", .Name = "Arizona"})
        states.Add(New State() With {.Abbreviation = "CA", .Name = "California"})
        states.Add(New State() With {.Abbreviation = "CO", .Name = "Colorado"})
        states.Add(New State() With {.Abbreviation = "CT", .Name = "Connecticut"})
        states.Add(New State() With {.Abbreviation = "DC", .Name = "District of Columbia"})
        states.Add(New State() With {.Abbreviation = "DE", .Name = "Delaware"})
        states.Add(New State() With {.Abbreviation = "FL", .Name = "Florida"})
        states.Add(New State() With {.Abbreviation = "GA", .Name = "Georgia"})
        states.Add(New State() With {.Abbreviation = "HI", .Name = "Hawaii"})
        states.Add(New State() With {.Abbreviation = "ID", .Name = "Idaho"})
        states.Add(New State() With {.Abbreviation = "IL", .Name = "Illinois"})
        states.Add(New State() With {.Abbreviation = "IN", .Name = "Indiana"})
        states.Add(New State() With {.Abbreviation = "IA", .Name = "Iowa"})
        states.Add(New State() With {.Abbreviation = "KS", .Name = "Kansas"})
        states.Add(New State() With {.Abbreviation = "KY", .Name = "Kentucky"})
        states.Add(New State() With {.Abbreviation = "LA", .Name = "Louisiana"})
        states.Add(New State() With {.Abbreviation = "ME", .Name = "Maine"})
        states.Add(New State() With {.Abbreviation = "MD", .Name = "Maryland"})
        states.Add(New State() With {.Abbreviation = "MA", .Name = "Massachusetts"})
        states.Add(New State() With {.Abbreviation = "MI", .Name = "Michigan"})
        states.Add(New State() With {.Abbreviation = "MN", .Name = "Minnesota"})
        states.Add(New State() With {.Abbreviation = "MS", .Name = "Mississippi"})
        states.Add(New State() With {.Abbreviation = "MO", .Name = "Missouri"})
        states.Add(New State() With {.Abbreviation = "MT", .Name = "Montana"})
        states.Add(New State() With {.Abbreviation = "NE", .Name = "Nebraska"})
        states.Add(New State() With {.Abbreviation = "NH", .Name = "New Hampshire"})
        states.Add(New State() With {.Abbreviation = "NJ", .Name = "New Jersey"})
        states.Add(New State() With {.Abbreviation = "NM", .Name = "New Mexico"})
        states.Add(New State() With {.Abbreviation = "NY", .Name = "New York"})
        states.Add(New State() With {.Abbreviation = "NC", .Name = "North Carolina"})
        states.Add(New State() With {.Abbreviation = "NV", .Name = "Nevada"})
        states.Add(New State() With {.Abbreviation = "ND", .Name = "North Dakota"})
        states.Add(New State() With {.Abbreviation = "OH", .Name = "Ohio"})
        states.Add(New State() With {.Abbreviation = "OK", .Name = "Oklahoma"})
        states.Add(New State() With {.Abbreviation = "OR", .Name = "Oregon"})
        states.Add(New State() With {.Abbreviation = "PA", .Name = "Pennsylvania"})
        states.Add(New State() With {.Abbreviation = "RI", .Name = "Rhode Island"})
        states.Add(New State() With {.Abbreviation = "SC", .Name = "South Carolina"})
        states.Add(New State() With {.Abbreviation = "SD", .Name = "South Dakota"})
        states.Add(New State() With {.Abbreviation = "TN", .Name = "Tennessee"})
        states.Add(New State() With {.Abbreviation = "TX", .Name = "Texas"})
        states.Add(New State() With {.Abbreviation = "UT", .Name = "Utah"})
        states.Add(New State() With {.Abbreviation = "VT", .Name = "Vermont"})
        states.Add(New State() With {.Abbreviation = "VA", .Name = "Virginia"})
        states.Add(New State() With {.Abbreviation = "WA", .Name = "Washington"})
        states.Add(New State() With {.Abbreviation = "WV", .Name = "West Virginia"})
        states.Add(New State() With {.Abbreviation = "WI", .Name = "Wisconsin"})
        states.Add(New State() With {.Abbreviation = "WY", .Name = "Wyoming"})
        Return states.ToList()
    End Function


I'd use a little library package, such as this one: https://www.nuget.org/packages/Archon.Enums.Geography/1.0.2


Here is a Country version for you.

public class WorldCountry
{
    public WorldCountry()
    {
        Name = null;
        Alpha2Code = null;
        Alpha3Code = null;
        NumericCode = null;
        Enabled = false;
    }

    public WorldCountry(string name, string alpha2Code, string alpha3Code, string numericCode, bool enabled)
    {
        Name = name;
        Alpha2Code = alpha2Code;
        Alpha3Code = alpha3Code;
        NumericCode = numericCode;
        Enabled = enabled;
    }

    public string Name { get; set; }
    public string Alpha2Code { get; set; }
    public string Alpha3Code { get; set; }
    public string NumericCode { get; set; }
    public bool Enabled { get; set; }

    public override string ToString()
    {
        //Returns "USA - United States"
        return string.Format("{0} - {1}", Alpha3Code, Name);
    }
}

public class CountryArray
{
    public List<WorldCountry> countries;
    public CountryArray()
    {
        countries = new List<WorldCountry>(50);
        countries.Add(new WorldCountry("Afghanistan", "AF", "AFG", "004", false));
        countries.Add(new WorldCountry("Aland Islands", "AX", "ALA", "248", false));
        countries.Add(new WorldCountry("Albania", "AL", "ALB", "008", false));
        countries.Add(new WorldCountry("Algeria", "DZ", "DZA", "012", false));
        countries.Add(new WorldCountry("American Samoa", "AS", "ASM", "016", false));
        countries.Add(new WorldCountry("Andorra", "AD", "AND", "020", false));
        countries.Add(new WorldCountry("Angola", "AO", "AGO", "024", false));
        countries.Add(new WorldCountry("Anguilla", "AI", "AIA", "660", false));
        countries.Add(new WorldCountry("Antarctica", "AQ", "ATA", "010", false));
        countries.Add(new WorldCountry("Antigua and Barbuda", "AG", "ATG", "028", false));
        countries.Add(new WorldCountry("Argentina", "AR", "ARG", "032", false));
        countries.Add(new WorldCountry("Armenia", "AM", "ARM", "051", false));
        countries.Add(new WorldCountry("Aruba", "AW", "ABW", "533", false));
        countries.Add(new WorldCountry("Australia", "AU", "AUS", "036", false));
        countries.Add(new WorldCountry("Austria", "AT", "AUT", "040", false));
        countries.Add(new WorldCountry("Azerbaijan", "AZ", "AZE", "031", false));
        countries.Add(new WorldCountry("Bahamas", "BS", "BHS", "044", false));
        countries.Add(new WorldCountry("Bahrain", "BH", "BHR", "048", false));
        countries.Add(new WorldCountry("Bangladesh", "BD", "BGD", "050", false));
        countries.Add(new WorldCountry("Barbados", "BB", "BRB", "052", false));
        countries.Add(new WorldCountry("Belarus", "BY", "BLR", "112", false));
        countries.Add(new WorldCountry("Belgium", "BE", "BEL", "056", false));
        countries.Add(new WorldCountry("Belize", "BZ", "BLZ", "084", false));
        countries.Add(new WorldCountry("Benin", "BJ", "BEN", "204", false));
        countries.Add(new WorldCountry("Bermuda", "BM", "BMU", "060", false));
        countries.Add(new WorldCountry("Bhutan", "BT", "BTN", "064", false));
        countries.Add(new WorldCountry("Bolivia, Plurinational State of", "BO", "BOL", "068", false));
        countries.Add(new WorldCountry("Bonaire, Sint Eustatius and Saba", "BQ", "BES", "535", false));
        countries.Add(new WorldCountry("Bosnia and Herzegovina", "BA", "BIH", "070", false));
        countries.Add(new WorldCountry("Botswana", "BW", "BWA", "072", false));
        countries.Add(new WorldCountry("Bouvet Island", "BV", "BVT", "074", false));
        countries.Add(new WorldCountry("Brazil", "BR", "BRA", "076", false));
        countries.Add(new WorldCountry("British Indian Ocean Territory", "IO", "IOT", "086", false));
        countries.Add(new WorldCountry("Brunei Darussalam", "BN", "BRN", "096", false));
        countries.Add(new WorldCountry("Bulgaria", "BG", "BGR", "100", false));
        countries.Add(new WorldCountry("Burkina Faso", "BF", "BFA", "854", false));
        countries.Add(new WorldCountry("Burundi", "BI", "BDI", "108", false));
        countries.Add(new WorldCountry("Cambodia", "KH", "KHM", "116", false));
        countries.Add(new WorldCountry("Cameroon", "CM", "CMR", "120", false));
        countries.Add(new WorldCountry("Canada", "CA", "CAN", "124", true));
        countries.Add(new WorldCountry("Cape Verde", "CV", "CPV", "132", false));
        countries.Add(new WorldCountry("Cayman Islands", "KY", "CYM", "136", false));
        countries.Add(new WorldCountry("Central African Republic", "CF", "CAF", "140", false));
        countries.Add(new WorldCountry("Chad", "TD", "TCD", "148", false));
        countries.Add(new WorldCountry("Chile", "CL", "CHL", "152", false));
        countries.Add(new WorldCountry("China", "CN", "CHN", "156", false));
        countries.Add(new WorldCountry("Christmas Island", "CX", "CXR", "162", false));
        countries.Add(new WorldCountry("Cocos (Keeling) Islands", "CC", "CCK", "166", false));
        countries.Add(new WorldCountry("Colombia", "CO", "COL", "170", false));
        countries.Add(new WorldCountry("Comoros", "KM", "COM", "174", false));
        countries.Add(new WorldCountry("Congo", "CG", "COG", "178", false));
        countries.Add(new WorldCountry("Congo, the Democratic Republic of the", "CD", "COD", "180", false));
        countries.Add(new WorldCountry("Cook Islands", "CK", "COK", "184", false));
        countries.Add(new WorldCountry("Costa Rica", "CR", "CRI", "188", false));
        countries.Add(new WorldCountry("Cote d'Ivoire", "CI", "CIV", "384", false));
        countries.Add(new WorldCountry("Croatia", "HR", "HRV", "191", false));
        countries.Add(new WorldCountry("Cuba", "CU", "CUB", "192", false));
        countries.Add(new WorldCountry("Curacao", "CW", "CUW", "531", false));
        countries.Add(new WorldCountry("Cyprus", "CY", "CYP", "196", false));
        countries.Add(new WorldCountry("Czech Republic", "CZ", "CZE", "203", false));
        countries.Add(new WorldCountry("Denmark", "DK", "DNK", "208", false));
        countries.Add(new WorldCountry("Djibouti", "DJ", "DJI", "262", false));
        countries.Add(new WorldCountry("Dominica", "DM", "DMA", "212", false));
        countries.Add(new WorldCountry("Dominican Republic", "DO", "DOM", "214", false));
        countries.Add(new WorldCountry("Ecuador", "EC", "ECU", "218", false));
        countries.Add(new WorldCountry("Egypt", "EG", "EGY", "818", false));
        countries.Add(new WorldCountry("El Salvador", "SV", "SLV", "222", false));
        countries.Add(new WorldCountry("Equatorial Guinea", "GQ", "GNQ", "226", false));
        countries.Add(new WorldCountry("Eritrea", "ER", "ERI", "232", false));
        countries.Add(new WorldCountry("Estonia", "EE", "EST", "233", false));
        countries.Add(new WorldCountry("Ethiopia", "ET", "ETH", "231", false));
        countries.Add(new WorldCountry("Falkland Islands (Malvinas)", "FK", "FLK", "238", false));
        countries.Add(new WorldCountry("Faroe Islands", "FO", "FRO", "234", false));
        countries.Add(new WorldCountry("Fiji", "FJ", "FJI", "242", false));
        countries.Add(new WorldCountry("Finland", "FI", "FIN", "246", false));
        countries.Add(new WorldCountry("France", "FR", "FRA", "250", false));
        countries.Add(new WorldCountry("French Guiana", "GF", "GUF", "254", false));
        countries.Add(new WorldCountry("French Polynesia", "PF", "PYF", "258", false));
        countries.Add(new WorldCountry("French Southern Territories", "TF", "ATF", "260", false));
        countries.Add(new WorldCountry("Gabon", "GA", "GAB", "266", false));
        countries.Add(new WorldCountry("Gambia", "GM", "GMB", "270", false));
        countries.Add(new WorldCountry("Georgia", "GE", "GEO", "268", false));
        countries.Add(new WorldCountry("Germany", "DE", "DEU", "276", false));
        countries.Add(new WorldCountry("Ghana", "GH", "GHA", "288", false));
        countries.Add(new WorldCountry("Gibraltar", "GI", "GIB", "292", false));
        countries.Add(new WorldCountry("Greece", "GR", "GRC", "300", false));
        countries.Add(new WorldCountry("Greenland", "GL", "GRL", "304", false));
        countries.Add(new WorldCountry("Grenada", "GD", "GRD", "308", false));
        countries.Add(new WorldCountry("Guadeloupe", "GP", "GLP", "312", false));
        countries.Add(new WorldCountry("Guam", "GU", "GUM", "316", false));
        countries.Add(new WorldCountry("Guatemala", "GT", "GTM", "320", false));
        countries.Add(new WorldCountry("Guernsey", "GG", "GGY", "831", false));
        countries.Add(new WorldCountry("Guinea", "GN", "GIN", "324", false));
        countries.Add(new WorldCountry("Guinea-Bissau", "GW", "GNB", "624", false));
        countries.Add(new WorldCountry("Guyana", "GY", "GUY", "328", false));
        countries.Add(new WorldCountry("Haiti", "HT", "HTI", "332", false));
        countries.Add(new WorldCountry("Heard Island and McDonald Islands", "HM", "HMD", "334", false));
        countries.Add(new WorldCountry("Holy See (Vatican City State)", "VA", "VAT", "336", false));
        countries.Add(new WorldCountry("Honduras", "HN", "HND", "340", false));
        countries.Add(new WorldCountry("Hong Kong", "HK", "HKG", "344", false));
        countries.Add(new WorldCountry("Hungary", "HU", "HUN", "348", false));
        countries.Add(new WorldCountry("Iceland", "IS", "ISL", "352", false));
        countries.Add(new WorldCountry("India", "IN", "IND", "356", false));
        countries.Add(new WorldCountry("Indonesia", "ID", "IDN", "360", false));
        countries.Add(new WorldCountry("Iran, Islamic Republic of", "IR", "IRN", "364", false));
        countries.Add(new WorldCountry("Iraq", "IQ", "IRQ", "368", false));
        countries.Add(new WorldCountry("Ireland", "IE", "IRL", "372", false));
        countries.Add(new WorldCountry("Isle of Man", "IM", "IMN", "833", false));
        countries.Add(new WorldCountry("Israel", "IL", "ISR", "376", false));
        countries.Add(new WorldCountry("Italy", "IT", "ITA", "380", false));
        countries.Add(new WorldCountry("Jamaica", "JM", "JAM", "388", false));
        countries.Add(new WorldCountry("Japan", "JP", "JPN", "392", false));
        countries.Add(new WorldCountry("Jersey", "JE", "JEY", "832", false));
        countries.Add(new WorldCountry("Jordan", "JO", "JOR", "400", false));
        countries.Add(new WorldCountry("Kazakhstan", "KZ", "KAZ", "398", false));
        countries.Add(new WorldCountry("Kenya", "KE", "KEN", "404", false));
        countries.Add(new WorldCountry("Kiribati", "KI", "KIR", "296", false));
        countries.Add(new WorldCountry("Korea, Democratic People's Republic of", "KP", "PRK", "408", false));
        countries.Add(new WorldCountry("Korea, Republic of", "KR", "KOR", "410", false));
        countries.Add(new WorldCountry("Kuwait", "KW", "KWT", "414", false));
        countries.Add(new WorldCountry("Kyrgyzstan", "KG", "KGZ", "417", false));
        countries.Add(new WorldCountry("Lao People's Democratic Republic", "LA", "LAO", "418", false));
        countries.Add(new WorldCountry("Latvia", "LV", "LVA", "428", false));
        countries.Add(new WorldCountry("Lebanon", "LB", "LBN", "422", false));
        countries.Add(new WorldCountry("Lesotho", "LS", "LSO", "426", false));
        countries.Add(new WorldCountry("Liberia", "LR", "LBR", "430", false));
        countries.Add(new WorldCountry("Libya", "LY", "LBY", "434", false));
        countries.Add(new WorldCountry("Liechtenstein", "LI", "LIE", "438", false));
        countries.Add(new WorldCountry("Lithuania", "LT", "LTU", "440", false));
        countries.Add(new WorldCountry("Luxembourg", "LU", "LUX", "442", false));
        countries.Add(new WorldCountry("Macao", "MO", "MAC", "446", false));
        countries.Add(new WorldCountry("Macedonia, the former Yugoslav Republic of", "MK", "MKD", "807", false));
        countries.Add(new WorldCountry("Madagascar", "MG", "MDG", "450", false));
        countries.Add(new WorldCountry("Malawi", "MW", "MWI", "454", false));
        countries.Add(new WorldCountry("Malaysia", "MY", "MYS", "458", false));
        countries.Add(new WorldCountry("Maldives", "MV", "MDV", "462", false));
        countries.Add(new WorldCountry("Mali", "ML", "MLI", "466", false));
        countries.Add(new WorldCountry("Malta", "MT", "MLT", "470", false));
        countries.Add(new WorldCountry("Marshall Islands", "MH", "MHL", "584", false));
        countries.Add(new WorldCountry("Martinique", "MQ", "MTQ", "474", false));
        countries.Add(new WorldCountry("Mauritania", "MR", "MRT", "478", false));
        countries.Add(new WorldCountry("Mauritius", "MU", "MUS", "480", false));
        countries.Add(new WorldCountry("Mayotte", "YT", "MYT", "175", false));
        countries.Add(new WorldCountry("Mexico", "MX", "MEX", "484", false));
        countries.Add(new WorldCountry("Micronesia, Federated States of", "FM", "FSM", "583", false));
        countries.Add(new WorldCountry("Moldova, Republic of", "MD", "MDA", "498", false));
        countries.Add(new WorldCountry("Monaco", "MC", "MCO", "492", false));
        countries.Add(new WorldCountry("Mongolia", "MN", "MNG", "496", false));
        countries.Add(new WorldCountry("Montenegro", "ME", "MNE", "499", false));
        countries.Add(new WorldCountry("Montserrat", "MS", "MSR", "500", false));
        countries.Add(new WorldCountry("Morocco", "MA", "MAR", "504", false));
        countries.Add(new WorldCountry("Mozambique", "MZ", "MOZ", "508", false));
        countries.Add(new WorldCountry("Myanmar", "MM", "MMR", "104", false));
        countries.Add(new WorldCountry("Namibia", "NA", "NAM", "516", false));
        countries.Add(new WorldCountry("Nauru", "NR", "NRU", "520", false));
        countries.Add(new WorldCountry("Nepal", "NP", "NPL", "524", false));
        countries.Add(new WorldCountry("Netherlands", "NL", "NLD", "528", false));
        countries.Add(new WorldCountry("New Caledonia", "NC", "NCL", "540", false));
        countries.Add(new WorldCountry("New Zealand", "NZ", "NZL", "554", false));
        countries.Add(new WorldCountry("Nicaragua", "NI", "NIC", "558", false));
        countries.Add(new WorldCountry("Niger", "NE", "NER", "562", false));
        countries.Add(new WorldCountry("Nigeria", "NG", "NGA", "566", false));
        countries.Add(new WorldCountry("Niue", "NU", "NIU", "570", false));
        countries.Add(new WorldCountry("Norfolk Island", "NF", "NFK", "574", false));
        countries.Add(new WorldCountry("Northern Mariana Islands", "MP", "MNP", "580", false));
        countries.Add(new WorldCountry("Norway", "NO", "NOR", "578", false));
        countries.Add(new WorldCountry("Oman", "OM", "OMN", "512", false));
        countries.Add(new WorldCountry("Pakistan", "PK", "PAK", "586", false));
        countries.Add(new WorldCountry("Palau", "PW", "PLW", "585", false));
        countries.Add(new WorldCountry("Palestine, State of", "PS", "PSE", "275", false));
        countries.Add(new WorldCountry("Panama", "PA", "PAN", "591", false));
        countries.Add(new WorldCountry("Papua New Guinea", "PG", "PNG", "598", false));
        countries.Add(new WorldCountry("Paraguay", "PY", "PRY", "600", false));
        countries.Add(new WorldCountry("Peru", "PE", "PER", "604", false));
        countries.Add(new WorldCountry("Philippines", "PH", "PHL", "608", false));
        countries.Add(new WorldCountry("Pitcairn", "PN", "PCN", "612", false));
        countries.Add(new WorldCountry("Poland", "PL", "POL", "616", false));
        countries.Add(new WorldCountry("Portugal", "PT", "PRT", "620", false));
        countries.Add(new WorldCountry("Puerto Rico", "PR", "PRI", "630", false));
        countries.Add(new WorldCountry("Qatar", "QA", "QAT", "634", false));
        countries.Add(new WorldCountry("Reunion", "RE", "REU", "638", false));
        countries.Add(new WorldCountry("Romania", "RO", "ROU", "642", false));
        countries.Add(new WorldCountry("Russian Federation", "RU", "RUS", "643", false));
        countries.Add(new WorldCountry("Rwanda", "RW", "RWA", "646", false));
        countries.Add(new WorldCountry("Saint Barthélemy", "BL", "BLM", "652", false));
        countries.Add(new WorldCountry("Saint Helena, Ascension and Tristan da Cunha", "SH", "SHN", "654", false));
        countries.Add(new WorldCountry("Saint Kitts and Nevis", "KN", "KNA", "659", false));
        countries.Add(new WorldCountry("Saint Lucia", "LC", "LCA", "662", false));
        countries.Add(new WorldCountry("Saint Martin (French part)", "MF", "MAF", "663", false));
        countries.Add(new WorldCountry("Saint Pierre and Miquelon", "PM", "SPM", "666", false));
        countries.Add(new WorldCountry("Saint Vincent and the Grenadines", "VC", "VCT", "670", false));
        countries.Add(new WorldCountry("Samoa", "WS", "WSM", "882", false));
        countries.Add(new WorldCountry("San Marino", "SM", "SMR", "674", false));
        countries.Add(new WorldCountry("Sao Tome and Principe", "ST", "STP", "678", false));
        countries.Add(new WorldCountry("Saudi Arabia", "SA", "SAU", "682", false));
        countries.Add(new WorldCountry("Senegal", "SN", "SEN", "686", false));
        countries.Add(new WorldCountry("Serbia", "RS", "SRB", "688", false));
        countries.Add(new WorldCountry("Seychelles", "SC", "SYC", "690", false));
        countries.Add(new WorldCountry("Sierra Leone", "SL", "SLE", "694", false));
        countries.Add(new WorldCountry("Singapore", "SG", "SGP", "702", false));
        countries.Add(new WorldCountry("Sint Maarten (Dutch part)", "SX", "SXM", "534", false));
        countries.Add(new WorldCountry("Slovakia", "SK", "SVK", "703", false));
        countries.Add(new WorldCountry("Slovenia", "SI", "SVN", "705", false));
        countries.Add(new WorldCountry("Solomon Islands", "SB", "SLB", "090", false));
        countries.Add(new WorldCountry("Somalia", "SO", "SOM", "706", false));
        countries.Add(new WorldCountry("South Africa", "ZA", "ZAF", "710", false));
        countries.Add(new WorldCountry("South Georgia and the South Sandwich Islands", "GS", "SGS", "239", false));
        countries.Add(new WorldCountry("South Sudan", "SS", "SSD", "728", false));
        countries.Add(new WorldCountry("Spain", "ES", "ESP", "724", false));
        countries.Add(new WorldCountry("Sri Lanka", "LK", "LKA", "144", false));
        countries.Add(new WorldCountry("Sudan", "SD", "SDN", "729", false));
        countries.Add(new WorldCountry("Suriname", "SR", "SUR", "740", false));
        countries.Add(new WorldCountry("Svalbard and Jan Mayen", "SJ", "SJM", "744", false));
        countries.Add(new WorldCountry("Swaziland", "SZ", "SWZ", "748", false));
        countries.Add(new WorldCountry("Sweden", "SE", "SWE", "752", false));
        countries.Add(new WorldCountry("Switzerland", "CH", "CHE", "756", false));
        countries.Add(new WorldCountry("Syrian Arab Republic", "SY", "SYR", "760", false));
        countries.Add(new WorldCountry("Taiwan, Province of China", "TW", "TWN", "158", false));
        countries.Add(new WorldCountry("Tajikistan", "TJ", "TJK", "762", false));
        countries.Add(new WorldCountry("Tanzania, United Republic of", "TZ", "TZA", "834", false));
        countries.Add(new WorldCountry("Thailand", "TH", "THA", "764", false));
        countries.Add(new WorldCountry("Timor-Leste", "TL", "TLS", "626", false));
        countries.Add(new WorldCountry("Togo", "TG", "TGO", "768", false));
        countries.Add(new WorldCountry("Tokelau", "TK", "TKL", "772", false));
        countries.Add(new WorldCountry("Tonga", "TO", "TON", "776", false));
        countries.Add(new WorldCountry("Trinidad and Tobago", "TT", "TTO", "780", false));
        countries.Add(new WorldCountry("Tunisia", "TN", "TUN", "788", false));
        countries.Add(new WorldCountry("Turkey", "TR", "TUR", "792", false));
        countries.Add(new WorldCountry("Turkmenistan", "TM", "TKM", "795", false));
        countries.Add(new WorldCountry("Turks and Caicos Islands", "TC", "TCA", "796", false));
        countries.Add(new WorldCountry("Tuvalu", "TV", "TUV", "798", false));
        countries.Add(new WorldCountry("Uganda", "UG", "UGA", "800", false));
        countries.Add(new WorldCountry("Ukraine", "UA", "UKR", "804", false));
        countries.Add(new WorldCountry("United Arab Emirates", "AE", "ARE", "784", false));
        countries.Add(new WorldCountry("United Kingdom", "GB", "GBR", "826", false));
        countries.Add(new WorldCountry("United States", "US", "USA", "840", true));
        countries.Add(new WorldCountry("United States Minor Outlying Islands", "UM", "UMI", "581", false));
        countries.Add(new WorldCountry("Uruguay", "UY", "URY", "858", false));
        countries.Add(new WorldCountry("Uzbekistan", "UZ", "UZB", "860", false));
        countries.Add(new WorldCountry("Vanuatu", "VU", "VUT", "548", false));
        countries.Add(new WorldCountry("Venezuela, Bolivarian Republic of", "VE", "VEN", "862", false));
        countries.Add(new WorldCountry("Viet Nam", "VN", "VNM", "704", false));
        countries.Add(new WorldCountry("Virgin Islands, British", "VG", "VGB", "092", false));
        countries.Add(new WorldCountry("Virgin Islands, U.S.", "VI", "VIR", "850", false));
        countries.Add(new WorldCountry("Wallis and Futuna", "WF", "WLF", "876", false));
        countries.Add(new WorldCountry("Western Sahara", "EH", "ESH", "732", false));
        countries.Add(new WorldCountry("Yemen", "YE", "YEM", "887", false));
        countries.Add(new WorldCountry("Zambia", "ZM", "ZMB", "894", false));
        countries.Add(new WorldCountry("Zimbabwe", "ZW", "ZWE", "716", false));
    }

    /// <summary>
    /// List of 3 digit abbreviated country codes
    /// </summary>
    /// <returns></returns>
    public string[] Alpha3Codes()
    {
        List<string> abbrevList = new List<string>(countries.Count);
        foreach (var country in countries)
        {
            if (country.Enabled)
                abbrevList.Add(country.Alpha3Code);
        }
        return abbrevList.ToArray();
    }

    /// <summary>
    /// List of 2 digit abbreviated country codes
    /// </summary>
    /// <returns></returns>
    public string[] Alpha2Codes()
    {
        List<string> abbrevList = new List<string>(countries.Count);
        foreach (var country in countries)
        {
            if (country.Enabled)
                abbrevList.Add(country.Alpha2Code);
        }
        return abbrevList.ToArray();
    }

    /// <summary>
    /// List of Country names
    /// </summary>
    /// <returns></returns>
    public string[] Names()
    {
        List<string> nameList = new List<string>(countries.Count);
        foreach (var country in countries)
        {
            if (country.Enabled)
                nameList.Add(country.Name);
        }
        return nameList.ToArray();
    }

    /// <summary>
    /// List of Countries
    /// </summary>
    /// <returns></returns>
    public WorldCountry[] Countries()
    {
        return countries.Where(c => c.Enabled == true).ToArray();
    }
}

I am also going to post this on my blog.


I took jp2code's answer and just made a tuple with it, rather than creating a new class and all of that... try this:

public static class StateArray
{
    public static List<(string Abbreviation, string Name)> States { get; }

    static StateArray()
    {
        States = new List<(string, string)>(50);
        States.Add(("AL", "Alabama"));
        States.Add(("AK", "Alaska"));
        States.Add(("AZ", "Arizona"));
        States.Add(("AR", "Arkansas"));
        States.Add(("CA", "California"));
        States.Add(("CO", "Colorado"));
        States.Add(("CT", "Connecticut"));
        States.Add(("DE", "Delaware"));
        States.Add(("DC", "District Of Columbia"));
        States.Add(("FL", "Florida"));
        States.Add(("GA", "Georgia"));
        States.Add(("HI", "Hawaii"));
        States.Add(("ID", "Idaho"));
        States.Add(("IL", "Illinois"));
        States.Add(("IN", "Indiana"));
        States.Add(("IA", "Iowa"));
        States.Add(("KS", "Kansas"));
        States.Add(("KY", "Kentucky"));
        States.Add(("LA", "Louisiana"));
        States.Add(("ME", "Maine"));
        States.Add(("MD", "Maryland"));
        States.Add(("MA", "Massachusetts"));
        States.Add(("MI", "Michigan"));
        States.Add(("MN", "Minnesota"));
        States.Add(("MS", "Mississippi"));
        States.Add(("MO", "Missouri"));
        States.Add(("MT", "Montana"));
        States.Add(("NE", "Nebraska"));
        States.Add(("NV", "Nevada"));
        States.Add(("NH", "New Hampshire"));
        States.Add(("NJ", "New Jersey"));
        States.Add(("NM", "New Mexico"));
        States.Add(("NY", "New York"));
        States.Add(("NC", "North Carolina"));
        States.Add(("ND", "North Dakota"));
        States.Add(("OH", "Ohio"));
        States.Add(("OK", "Oklahoma"));
        States.Add(("OR", "Oregon"));
        States.Add(("PA", "Pennsylvania"));
        States.Add(("RI", "Rhode Island"));
        States.Add(("SC", "South Carolina"));
        States.Add(("SD", "South Dakota"));
        States.Add(("TN", "Tennessee"));
        States.Add(("TX", "Texas"));
        States.Add(("UT", "Utah"));
        States.Add(("VT", "Vermont"));
        States.Add(("VA", "Virginia"));
        States.Add(("WA", "Washington"));
        States.Add(("WV", "West Virginia"));
        States.Add(("WI", "Wisconsin"));
        States.Add(("WY", "Wyoming"));
    }

    public static string[] Abbreviations()
    {
        List<string> abbrevList = new List<string>(States.Count);
        foreach (var state in States)
        {
            abbrevList.Add(state.Abbreviation);
        }
        return abbrevList.ToArray();
    }

    public static string[] Names()
    {
        List<string> nameList = new List<string>(States.Count);
        foreach (var state in States)
        {
            nameList.Add(state.Name);
        }
        return nameList.ToArray();
    }
}


StateInfo[] state_list = {
                new states.add(new StateInfo ("AL","Alabama","Montgomery","Yellowhammer","Camellia","4849377","Birmingham","32.738772","86.638184","52423","December 14, 1819","2,407 feet","Sea level","500 feet","907","Audemus Jura Nostra Defendere","7"," Yellowhammer State","George Washington Carver, who discovered more than 300 uses for peanuts","Longleaf Pine Pinaceae Pinus palustris ","Based on the Choctaw word albah amo meaning 'thicket clearers'",R.drawable.al));

    states.add(new StateInfo("AK","Alaska","Juneau","Willow Ptarmigan","ForgetMeNot","736732","Anchorage","66.160507","153.369141","656424","January 3, 1959","20,320 feet","Sea level","1,900 feet","205, 251, 256, 334","North to the Future","7","The Last Frontier ","The longest coastline in the U.S., 6,640 miles, greater than that of all other states combined","Sitka Spruce (Picea sitchensis) ","Based on an Aleut word alaxsxaq literally meaning 'object toward which the action of the sea is directed' or more simply, 'the mainland'",R.drawable.ak));
    states.add(new StateInfo("AZ","Arizona","Phoenix","Cactus Wren","Saguaro Cactus Blossom","6731484","Phoenix","34.048927","111.093735","114006","February 14, 1912","12,633 feet","70 feet","4,100 feet","479, 501, 870","Ditat Deus","7","The Grand Canyon State","The most telescopes in the world, in Tucson","Yellow Palo Verde (Parkinsonia microphylla) ","Based on the Basque word aritz onak meaning 'good oak' or the Spanish word Arizonac meaning 'having a little spring'",R.drawable.az));
    states.add(new StateInfo("AR","Arkansas","Little Rock","Mockingbird","Apple Blossom","2966369","Little Rock","34.820568","91.999512","53182","June 15, 1836","2,753 feet","55 feet","650 feet","480, 520, 602, 623, 928","Regnat Populus","7","The Natural State","The only active diamond mine in the U.S.","Loblolly Pine (Pinus taeda) ","French interpretation of a Sioux word acansa meaning 'downstream people'",R.drawable.ak));
    states.add(new StateInfo("CA","California","Sacramento","California Valley Quail","Golden Poppy","38802500","Los Angeles","36.778259","119.417931","163707","September 9, 1850","14,494 feet","282 feet","2,900 feet","209, 213, 310, 323, 408, 415, 510, 530, 559, 562, 619, 626, 650, 661, 707, 714, 760, 805, 818, 831, 858, 909, 916, 925, 949, 951","Eureka","6L","Golden State","'General Sherman', a 3,500yearold tree, and a stand of bristlecone pines 4,000 years old are the world's oldest living things","California Redwood (Sequoia sempervirens & Sequoia gigantea) ","Named by the Spanish after Califia, a mythical paradise in a Spanish romance, written by Montalvo in 1510. ",R.drawable.ca));
    states.add(new StateInfo("CO","Colorado","Denver","Lark Bunting","Rocky Mountain Columbine","5355866","Denver","39.113014","105.358887","104100","August 1, 1876","14,440 feet","3,315 feet","6,800 feet","303, 719, 970","Nil Sine Numine","6","Centennial State","The world's largest silver nugget (1,840 pounds) found in 1894 near Aspen","Colorado Blue Spruce (Picea pugens) ","Taken from the Spanish for the color red, referring to the banks of the Colorado river. ",R.drawable.co));
    states.add(new StateInfo("CT","Connecticut","Hartford","Robin","Mountain Laurel","3596677","Bridgeport","41.481833","72.663574","5544","January 9, 1788","2,380 feet","Sea level","500 feet","203, 860","Qui Transtulit Sustinet","6","Constitution State","The first American cookbook, published in Hartford in 1796: American Cookery by Amelia Simmons","White Oak(Quercus alba) ","From the Eastern Algonquin Indian word quinnitukqut meaning 'at the long tidal river', referring to the Connecticut River ",R.drawable.ct));
    states.add(new StateInfo("DE","Delaware","Dover","Blue Hen Chicken","Peach Blossom","935614","Wilmington","39.102357","75.388184","2489","December 7, 1787","450 feet","Sea level","60 feet","302","Liberty and independence","6L","Blue Hen State","The first log cabins in North America, built in 1683 by Swedish immigrants","American Holly(Ilex opaca) ","Named after an early Virginia governor, Lord de la Warr ",R.drawable.de));
    states.add(new StateInfo("FL","Florida","Tallahassee","Mockingbird","Orange Blossom","19893297","Jacksonville","28.659261","81.89209","59988","March 3, 1845","345 feet","Sea level","100 feet","239, 305, 321, 352, 386, 407, 561, 727, 772, 813, 850, 863, 904, 941, 954","In God we trust","7","Sunshine State","U.S. spacecraft launchings from Cape Canaveral, formerly Cape Kennedy","Sabal Palm (Sabal palmetto) ","Named on Easter 1513 by Ponce de Leon for Pascua Florida, meaning 'Flowery Easter' ",R.drawable.fl));
    states.add(new StateInfo("GA","Georgia","Atlanta","Brown Thrasher","Cherokee Rose","10097343","Atlanta","33.247875","83.441162","59441","January 2, 1788","4,784 feet","Sea level","600 feet","229, 404, 478, 706, 770, 912","Wisdom, Justice, and Moderation","7","Peach State","The Girl Scouts, founded in Savannah by Juliette Gordon Low in 1912","Southern Live Oak(Quercus virginiana) ","Named for King George II of England ",R.drawable.ga));
    states.add(new StateInfo("HI","Hawaii","Honolulu","Nene","Hawaiian Hibiscus","1419561","Honolulu","21.289373","157.91748","6459","August 21, 1959","13,796 feet","Sea level","3,030 feet","808","Agriculture and Commerce","","Aloha State","The only royal palace in the U.S. (Iolani)","Candlenut Tree (Aleurites moluccana) ","Could be based on native Hawaiian word for homeland, Owhyhee ",R.drawable.hi));
    states.add(new StateInfo("ID","Idaho","Boise","Mountain Bluebird","Syringa, mock orange","1634464","Boise","44.068203","114.742043","83574","July 3, 1890","12,662 feet","710 feet","5,000 feet","319, 515, 563, 641, 712","Esto Perpetua","7","Gem State","The longest main street in America, 33 miles, in Island Park","Western White Pine(Pinus monticola) ","Idaho is a coined, or invented, word ",R.drawable.id));
    states.add(new StateInfo("IL","Illinois","Springfield","Cardinal","Violet","12880580","Chicago","40.185168","89.143066","57918","December 3, 1818","1,235 feet","279 feet","600 feet","208","State sovereignty, national union","7","Prairie State","The tallest building in the U.S., Sears Tower, in Chicago","White Oak(Quercus alba) ","Based on the Algonquin Indian word ilenweewa meaning 'warriors'",R.drawable.il));
    states.add(new StateInfo("IN","Indiana","Indianapolis","Cardinal","Peony","6596855","Indianapolis","40.267193","86.134903","36420","December 11, 1816","1,257 feet","320 feet","700 feet","217, 309, 312, 618, 630, 708, 773, 815, 847","The crossroads of America","","Hoosier State","The famous car race: the Indy 500","Tulip Tree (Liriodendron tulipifera) ","Latin for 'Land of the Indians'",R.drawable.in));
    states.add(new StateInfo("IA","Iowa","Des Moines","Eastern Goldfinch","Wild Prairie Rose","3107126","Des Moines","42.032974","93.581543","56276","December 28, 1846","1,670 feet","480 feet","1,100 feet","219, 260, 317, 574, 765, 812","Our liberties we prize and our rights we will maintain","7","Hawkeye State","The shortest and steepest railroad in the U.S., Dubuque: 60 incline, 296 feet","Bur Oak (Quercus macrocarpa) ","The name Iowa comes from Ioway, the French word for the Bahkhoje Indian tribe that lived in the area. ",R.drawable.ia));
    states.add(new StateInfo("KS","Kansas","Topeka","Western Meadowlark","Sunflower","2904021","Wichita","38.588967","98.415527","82282","January 29, 1861","4,039 feet","679 feet","2,000 feet","316, 620, 785, 913","Ad Astra per Aspera","6","Sunflower State","Helium discovered in 1905 at the University of Kansas","Eastern Cottonwood(Populus deltoides) ","From the Sioux Indian for 'south wind people'",R.drawable.ks));
    states.add(new StateInfo("KY","Kentucky","Frankfort","Cardinal","Goldenrod","4413457","Louisville","37.839333","84.27002","40411","June 1, 1792","4,139 feet","257 feet","750 feet","270, 502, 606, 859","United we stand, divided we shall fall","","Bluegrass State","The largest underground cave in the world: 300 miles long, the MammothFlint Cave system","Tulip Tree (Liriodendron tulipifera) ","Based on the Iroquois Indian word Kentahten meaning 'land of tomorrow' ",R.drawable.ky));
    states.add(new StateInfo("LA","Louisiana","Baton Rouge","Eastern Brown Pelican","Magnolia","4649676","New Orleans","31.398191","92.658691","51843","April 30, 1812","535 feet","8 feet","100 feet","225, 318, 337, 504, 985","Union, justice, confidence ","7","Pelican State","The most crayfish: 98% of the world's crayfish","Bald Cypress(Taxodium distichum) ","Named in honor of France's King Louis XIV ",R.drawable.la));
    states.add(new StateInfo("ME","Maine","Augusta","Chickadee","Pine Cone and Tassel","1330089","Portland","45.187844","68.972168","35387","March 15, 1820","5,276 feet","Sea level","600 feet","413, 508, 617, 781, 978","Dirigo","","Pine Tree State","The most easterly point in the U.S., West Quoddy Head1","Eastern White Pine(Pinus strobus) ","Assumed to be a reference to the state region being a mainland, different from its many surrounding islands ",R.drawable.me));
    states.add(new StateInfo("MD","Maryland","Annapolis","Baltimore Oriole","BlackEyed Susan","5976407","Baltimore","39.045753","76.641273","12407","April 28, 1788","3,360 feet","Sea level","350 feet","301, 410","Fatti Maschii Parole Femine","","Old Line State","The first umbrella factory in the U.S., 1928, Baltimore","White Oak(Quercus alba) ","Named to honor Henrietta Maria, wife of England's King Charles ",R.drawable.md));
    states.add(new StateInfo("MA","Massachusetts","Boston","Chickadee","Mayflower","6745408","Boston","42.407211","71.382439","10555","February 6, 1788","3,487 feet","Sea level","500 feet","207","Ense Petit Placidam Sub Libertate Quietem","","Bay State","The first World Series, 1903: the Boston 'Americans' became the Red Sox in 1908) vs. the Pittsburg Pirates (Pittsburgh had no 'h' between 1890 1911)","American Elm(Ulmus americana) ","Based on the Algonquin Indian word massachussett meaning 'near the great little mountain'",R.drawable.ma));
    states.add(new StateInfo("MI","Michigan","Lansing","Robin","Apple Blossom","9909877","Detroit","43.522663","84.70459","96810","Jan 26, 1837","1,979 feet","572 feet","900 feet","231, 248, 269, 313, 517, 586, 616, 734, 810, 906, 989","Si Quaeris Peninsulam Amoenam Circumspice","","Wolverine State","The Cereal Bowl of America, Battle Creek, produces most cereal in the U.S.","Eastern White Pine(Pinus strobus) ","Based on the Ojibwa Indian word misshikama meaning 'great water', referring to the Great Lakes ",R.drawable.mi));
    states.add(new StateInfo("MN","Minnesota","Saint Paul","Common Loon","Pink and White Lady's Slipper","5457173","Minneapolis","46.392410","94.63623","86943","May 11, 1858","2,301 feet","602 feet","1,200 feet","218, 320, 507, 612, 651, 763, 952","L'Etoile du Nord","7R","Land of 10,000 Lakes","The oldest rock in the world, 3.8 billion years old, found in Minnesota River valley","Red Pine(Pinus resinosa) ","Based on the Dakota Sioux Indian word mnisota for 'skytinted water', referring to the Minnesota River ",R.drawable.mn));
    states.add(new StateInfo("MS","Mississippi","Jackson","Mockingbird","Magnolia","2994079","Jackson","32.701800","89.626465","48434","December 10, 1817","806 feet","Sea level","300 feet","314, 417, 573, 636, 660, 816","Virtute et Armis","7","Magnolia State","CocaCola, first bottled in 1894 in Vicksburg","Southern Magnolia(Magnolia grandiflora) ","Based on the Ojibwa Indian word messipi meaning 'big river' ",R.drawable.ms));
    states.add(new StateInfo("MO","Missouri","Jefferson City","Bluebird","Hawthorn","6063589","Kansas City","38.313646","92.702637","69709","August 10, 1821","1,772 feet","230 feet","800 feet","228, 601, 662","Salus Populi Suprema Lex Esto","7","Show Me State","Mark Twain and some of his characters, such as Tom Sawyer and Huckleberry Finn","Flowering Dogwood(Cornus florida) ","Named after Missouri Indian tribe whose name means 'town of the large canoes'",R.drawable.mo));
    states.add(new StateInfo("MT","Montana","Helena","Western Meadowlark","Bitterroot","1023579","Billings","46.965260","109.533691","147046","November 8, 1889","12,799 feet","1,800 feet","3,400 feet","406","Oro y Plata","6","Treasure State","Grasshopper Glacier, named for the grasshoppers that can still be seen frozen in ice","Ponderosa Pine (Pinus ponderosa) ","Based on the Spanish word monta a meaning 'mountain'",R.drawable.mt));
    states.add(new StateInfo("NE","Nebraska","Lincoln","Western Meadowlark","Goldenrod","1881503","Omaha","41.317013","99.558105","77358","March 1, 1867","5,424 feet","840 feet","2,600 feet","252, 336, 704, 828, 910, 919","Equality before the law","6","Cornhusker State","The only roller skating museum in the world, in Lincoln","Eastern Cottonwood(Populus deltoides) ","Name based on an Otoe Indian word meaning 'flat water', referring to the Platte River ",R.drawable.ne));
    states.add(new StateInfo("NV","Nevada","Carson City","Mountain Bluebird","Sagebrush","2839099","Las Vegas","39.442557","116.784668","110567","October 31, 1864","13,140 feet","479 feet","5,500 feet","701","All for our country","6L","The Silver State","Rare fish such as the Devils Hole pup, found only in Devils Hole, and other rare fish from prehistoric lakes; also the driest state","SingleLeaf Pinon & Bristlecone Pine (Pinus monophylla & Pinus longaeva) "," Nevada is from the Spanish word meaning 'snowcapped'.",R.drawable.nv));
    states.add(new StateInfo("NH","New Hampshire","Concord","Purple Finch","Purple Lilac","1326813","Manchester","43.458900","71.696777","9351","June 21, 1788","6,288 feet","Sea level","1,000 feet","308, 402","Live free or die","","Granite State","Artificial rain, first used near Concord in 1947 to fight a forest fire","Paper Birch (Betula papyrifera) ","From the English county of Hampshire",R.drawable.nh));
    states.add(new StateInfo("NJ","New Jersey","Trenton","Eastern Goldfinch","Violet","8938175","Newark","39.833851","74.871826","8722",".incember 18, 1787","1,803 feet","Sea level","250 feet","603","Liberty and Prosperity","","Gar.inn State","The world's first drivein movie theater, built in 1933 near Cam.inn","Northern Red Oak (Quercus rubra) ","From the Channel Isle of Jersey",R.drawable.nj));
    states.add(new StateInfo("NM","New Mexico","Albany","Roadrunner","Yucca Flower","2085572","Albuquerque","34.307144","106.018066","121598","January 6, 1912","13,161 feet","2,842 feet","5,700 feet","201, 609, 732, 856, 908, 973","Crescit Eundo","7","Land of Enchantment","'Smokey Bear', a cub orphaned by fire in 1950, buried in Smokey Bear Historical State Park in1976","Pi on Tree (Pinus edulis) ","Named by the Spanish for lands north of the Rio Grande River ",R.drawable.nm));
    states.add(new StateInfo("NY","New York","Santa Fe","Bluebird","Rose","19746227","New York","42.882002","75.256348","54475","July 26, 1788","5,344 feet","Sea level","1,000 feet","505, 575","Excelsior","7","Empire State","The first presidential inauguration: George Washington took the oath of office in New York City on April 30, 1789.","Sugar Maple(Acer saccharum) ","In honor of the Duke of York",R.drawable.ny));
    states.add(new StateInfo("NC","North Carolina","Raleigh","Cardinal","Flowering Dogwood","9943964","Charlotte","35.782169","80.793457","52672","November 21, 1789","6,684 feet","Sea level","700 feet","702, 775","Esse Quam Videri","7","Tar Heel State","Virginia Dare, the first English child born in America, on Roanoake Island in 1587","Longleaf Pine(Pinus palustris) ","Taken from Carolus, the Latin word for Charles, and named after England's King Charles I ",R.drawable.nc));
    states.add(new StateInfo("ND","North Dakota","Bismark","Western Meadowlark","Wild Praire Rose","739482","Fargo","47.650589","100.437012","70704","November 2, 1889","3,506 feet","750 feet","1,900 feet","212, 315, 516, 518, 585, 607, 631, 716, 718, 845, 914","Liberty and union, now and forever, one and inseparable","6","Peace Garden State","The geographic center of North America, in Pierce County, near Balta","American Elm (Ulmus americana) ","Based on the Sioux Indian word dakhota meaning 'friend'",R.drawable.nd));
    states.add(new StateInfo("OH","Ohio","Columbus","Cardinal","Scarlet Carnation","11594163","Columbus","40.620207","82.770996","44828","March 1, 1803","1,549 feet","455 feet","850 feet","216, 330, 419, 440, 513, 614, 740, 937","With God, all things are possible","7","Buckeye State","The first electric traffic lights, invented and installed in Cleveland in 1914","Ohio Buckeye (Aesculus glabra) ","From an Iroquoian word meaning 'great river'",R.drawable.oh));
    states.add(new StateInfo("OK","Oklahoma","Oklahoma City","Scissortailed Flycatcher","Oklahoma Rose","3878051","Oklahoma City","36.084621","96.921387","69903","November 16, 1907","4,973 feet","289 feet","1,300 feet","405, 580, 918","Labor Omnia Vincit","6","Sooner State","The first parking meter, installed in Oklahoma City in 1935","Eastern Redbud(Cercis canadensis) ","From two Choctaw Indian words meaning 'red people'.",R.drawable.ok));
    states.add(new StateInfo("OR","Oregon","Salem","Western Meadowlark","Oregon Grape","3970239","Portland","43.745305","120.739746","98386","February 14, 1859","11,239 feet","Sea level","3,300 feet","503, 541","Alis Volat Propriis","6","Beaver State","The world's smallest park, totaling 452 inches, created in Portland on St. Patrick's Day for leprechauns and snail races","Douglas Fir(Pseudotsuga menziesii) ","Unknown. However, it is generally accepted that the name, first used by Jonathan Carver in 1778, was taken from the writings of Maj. Robert Rogers, an English army officer.",R.drawable.or));
    states.add(new StateInfo("PA","Pennsylvania","Harrisburg","Ruffed Grouse","Mountain Laurel","12787209","Philadelphia","41.203323","77.194527","46058","December 12, 1787","3,213 feet","Sea level","1,100 feet","215, 412, 570, 610, 717, 724, 814","Virtue, liberty and independence","7","Keystone State","The first magazine in America: the American Magazine, published in Philadelphia for 3 months in1741","Eastern Hemlock(Tsuga canadensis) ","In honor of Adm. Sir William Penn, father of William Penn. It means 'Penn's Woodland.'",R.drawable.pa));
    states.add(new StateInfo("RI","Rhode Island","Providence","Rhode Island Red","Violet","1055173","Providence","41.514747","71.38916","1545","May 29, 1790","812 feet","Sea level","200 feet","401","Hope","","The Ocean State","Rhode Island Red chickens, first bred in 1854; the start of poultry as a major American industry","Red Maple(Acer rubrum) ","Possibly named in honor of the Greek Island of Rhodes or was named Roode Eylandt by Adriaen Block, Dutch explorer, because of its red clay ",R.drawable.ri));
    states.add(new StateInfo("SC","South Carolina","Columbia","Great Carolina Wren","Yellow Jessamine","4832482","Columbia","33.836082","81.163727","32007","May 23, 1788","3,560 feet","Sea level","350 feet","803, 843, 864","Dum spiro spero Animis opibusque parati","","Palmetto State","The first tea farm in the U.S., created in 1890 near Summerville","Sabal Palm (Sabal palmetto) ","Taken from Carolus, the Latin word for Charles, and named after England's King Charles I ",R.drawable.sc));
    states.add(new StateInfo("SD","South Dakota","Pierre","Ringnecked Pheasant","Pasque Flower","853175","Sioux Falls","44.251101","100.217285","77121","November 2, 1889","7,242 feet","966 feet","2,200 feet","605","Under God, the people rule","6","Mount Rushmore State","The world's largest natural, indoor warmwater pool, Evans' Plunge in Hot Springs","White Spruce(Picea glauca) ","From the Sioux tribe, meaning 'allies'",R.drawable.sd));
    states.add(new StateInfo("TN","Tennessee","Nashville","Mockingbird","Purple Passionflower","6549352","Memphis","35.860119","86.660156","42146","June 1, 1796","6,643 feet","178 feet","900 feet","423, 615, 731, 865, 901, 931","Agriculture and commerce","7","Volunteer State","Graceland, the estate and gravesite of Elvis Presley","Tulip Tree (Liriodendron tulipfera) ","Of Cherokee origin; the exact meaning is unknown",R.drawable.tn));
    states.add(new StateInfo("TX","Texas","Austin","Mockingbird","Bluebonnet Sp.","26956958","Houston","31.360673","99.338379","268601","December 29, 1845","8,749 feet","Sea level","1,700 feet","210, 214, 254, 281, 325, 361, 409, 432, 512, 713, 806, 817, 830, 903, 915, 936, 940, 956, 972, 979","Friendship","","Lone Star State","NASA, in Houston, headquarters for all piloted U.S. space projects","Pecan(Carya illinoinensis) ","From an Indian word meaning 'friends'",R.drawable.tx));
    states.add(new StateInfo("UT","Utah","Salt Lake City","Common American Gull","Sego Lily","2942902","Salt Lake City","39.419220","111.950684","84904","January 4, 1896","13,528 feet","2,000 feet","6,100 feet","435, 801","Industry","7","The Beehive State","Rainbow Bridge, the largest natural stone bridge in the world, 290 feet high, 275 feet across","Quaking Aspen (Populus tremuloides) "," ",R.drawable.ut));
    states.add(new StateInfo("VT","Vermont","Montpelier","Hermit Thrush","Red Clover","626562","Burlington","43.903829","72.79541","9615","March 4, 1791","4,393 feet","95 feet","1,000 feet","276, 434, 540, 703, 757, 804","Freedom and Unity","","Green Mountain State","The largest production of maple syrup in the U.S.","Sugar Maple (Acer saccharum) ","From the French 'vert mont', meaning 'green mountain'",R.drawable.vt));
    states.add(new StateInfo("VA","Virginia","Richmond","Cardinal","American Dogwood","8326289","Virginia Beach","37.926868","78.024902","42769","June 25, 1788","5,729 feet","Sea level","950 feet","802","Sic semper tyrannis ","7","Old Dominion State","The only fulllength statue of George Washington, placed in capitol in 1796","Flowering Dogwood(Cornus florida) ","In honor of Elizabeth 'Virgin Queen' of England",R.drawable.va));
    states.add(new StateInfo("WA","Washington","Olympia","Willow Goldfinch","Coast Rhododendrum","7061530","Seattle","47.751076","120.740135","71303","November 11, 1889","14,410 feet","Sea level","1,700 feet","206, 253, 360, 425, 509","Alki","6","The Evergreen State","Lunar Rover, the vehicle used by astronauts on the moon; Boeing, in Seattle, makes aircraft and spacecraft","Western Hemlock(Tsuga heterophylla) ","In honor of George Washington",R.drawable.wa));
    states.add(new StateInfo("WV","West Virginia","Charleston","Cardinal","Rhododendron","1850326","Charleston","38.657633","80.617676","24231","June 20, 1863","4,863 feet","240 feet","1,500 feet","262, 414, 608, 715, 920","Montani Semper Liberi","","Mountain State","Marbles; most of the country's glass marbles made around Parkersburg","Sugar Maple(Acer saccharum) ","In honor of Elizabeth, 'Virgin Queen' of England",R.drawable.wv));
    states.add(new StateInfo("WI","Wisconsin","Madison","Robin","Wood Violet","5757564","Milwaukee","44.376877","89.758301","65503","May 29, 1848","1,951 feet","581 feet","1,050 feet","304","Forward","7","Badger State","The typewriter, invented in Milwaukee in 1867","Sugar Maple(Acer saccharum) ","Based on an Indian word Ouisconsin believed to mean 'grassy place'",R.drawable.wi));
    states.add(new StateInfo("WY","Wyoming","Cheyenne","Western Meadowlark","Indian Paintbrush","584153","Cheyenne","43.075970","107.290283","97818","July 10, 1890","13,804 feet","3,099 feet","6,700 feet","307","Equal rights","6","Equality State","The 'Register of the Desert' a huge granite boulder covering 27 acres with 5,000 early pioneer names carved on it","Eastern Cottonwood (Populus deltoides) ","From the Delaware Indian word, meaning 'mountains and valleys alternating'; the same as the Wyoming Valley in Pennsylvania",R.drawable.wy));
        };

Note: drawables can be any state related png such as license plate, map, quarter, etc.

StateInfo.java

public class StateInfo {
    private String abbreviation;
    private String stateName;
    private String capitol;
    private String bird;
    private String flower;
    private String population;
    private String largestcity;
    private String latitude;
    private String longitude;
    private String squaremiles;
    private String admittedtounion;
    private String highestpoint;
    private String lowestpoint;
    private String medianaltitude;
    private String areacodes;
    private String motto;
    private String magnify;
    private String nickname;
    private String facts;
    private String tree;
    private String originofname;

    public StateInfo(String abbreviation,
                     String stateName,
                     String capitol,
                     String bird,
                     String flower,
                     String population,
                     String largestcity,
                     String latitude,
                     String longitude,
                     String squaremiles,
                     String admittedtounion,
                     String highestpoint,
                     String lowestpoint,
                     String medianaltitude,
                     String areacodes,
                     String motto,
                     String magnify,
                     String nickname,
                     String facts,
                     String tree,
                     String originofname
    ) {
        super();

        this.abbreviation = abbreviation;
        this.stateName = stateName;
        this.capitol = capitol;
        this.bird = bird;
        this.flower = flower;
        this.population = population;
        this.largestcity = largestcity;
        this.latitude = latitude;
        this.longitude = longitude;
        this.squaremiles = squaremiles;
        this.admittedtounion = admittedtounion;
        this.highestpoint = highestpoint;
        this.lowestpoint = lowestpoint;
        this.medianaltitude = medianaltitude;
        this.areacodes = areacodes;
        this.motto=motto;
        this.magnify=magnify;
        this.nickname=nickname;
        this.facts=facts;
        this.tree=tree;
        this.originofname=originofname;
    }

    public String getStateName() {
        return stateName;
    }

    public void setStateName(String stateName) {this.stateName = stateName;    }

    public String getAbbreviation() {
        return abbreviation;
    }

    public void setAbbreviation(String abbreviation) {
        this.abbreviation = abbreviation;
    }
    public String getCapitol() {
        return capitol;
    }

    public void setCapitol(String capitol) {
        this.capitol = capitol;
    }

    public String getBird() {
        return bird;
    }

    public void setBird(String bird) {
        this.bird = bird;
    }
    public String getFlower() {
        return flower;
    }

    public void setFlower(String flower) {
        this.flower = flower;
    }
    public String getPopulation() {
        return population;
    }

    public void setPopulation(String population) {
        this.population = population;
    }
    public String getLargestcity() {
        return largestcity;
    }

    public void setLargestcity(String largestcity) {
        this.largestcity = largestcity;
    }
    public String getLatitude() {
        return latitude;
    }

    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }
    public String getLongitude() {
        return longitude;
    }

    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }
    public String getSquaremiles() {
        return squaremiles;
    }

    public void setSquaremiles(String squaremiles) {
        this.squaremiles = squaremiles;
    }
    public String getAdmittedtounion() {
        return admittedtounion;
    }

    public void setAdmittedtounion(String admittedtounion) {
        this.admittedtounion = admittedtounion;
    }
    public String getHighestpoint() {
        return highestpoint;
    }

    public void setHighestpoint(String highestpoint) {
        this.highestpoint = highestpoint;
    }
    public String getLowestpoint() {
        return lowestpoint;
    }

    public void setLowestpoint(String lowestpoint) {
        this.lowestpoint = lowestpoint;
    }
    public String getMedianaltitude() {
        return medianaltitude;
    }

    public void setMedianaltitude(String medianaltitude) {
        this.medianaltitude = medianaltitude;
    }
    public String getAreacodes() {
        return areacodes;
    }

    public void setAreacodes(String areacodes) {
        this.areacodes = areacodes;
    }
    public String getMotto() {
        return motto;
    }

    public void setMotto(String motto) {
        this.motto = motto;
    }
    public String getMagnify() {
        return magnify;
    }

    public void setMagnify(String magnify) {
        this.magnify = magnify;
    }
    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }
    public String getFacts() {
        return facts;
    }

    public void setFacts(String facts) {
        this.facts = facts;
    }
    public String getTree() {
        return tree;
    }

    public void setTree(String tree) {
        this.tree = tree;
    }
    public String getOriginofname() {
        return originofname;
    }

    public void setOriginofname(String originofname) {
        this.originofname = originofname;
    }
}


Here is the code done in a HashSet of SelectListItem

 public HashSet<SelectListItem> GetAllStates()
    {
        var states = new HashSet<SelectListItem>()
        {
            new SelectListItem() { ItemValue = "AL", Name = "Alabama" },
            new SelectListItem() { ItemValue = "AK", Name = "Alaska" },
            new SelectListItem() { ItemValue = "AZ", Name = "Arizona" }, 
            new SelectListItem() { ItemValue = "AR", Name = "Arkansas" },
            new SelectListItem() { ItemValue = "CA", Name = "California" },
            new SelectListItem() { ItemValue = "CO", Name = "Colorado" },
            new SelectListItem() { ItemValue = "CT", Name = "Connecticut" },
            new SelectListItem() { ItemValue = "DE", Name = "Delaware" },
            new SelectListItem() { ItemValue = "DC", Name = "District Of Columbia" },
            new SelectListItem() { ItemValue = "FL", Name = "Florida" },
            new SelectListItem() { ItemValue = "GA", Name = "Georgia" },
            new SelectListItem() { ItemValue = "HI", Name = "Hawaii" },
            new SelectListItem() { ItemValue = "ID", Name = "Idaho" },
            new SelectListItem() { ItemValue = "IL", Name = "Illinois" },
            new SelectListItem() { ItemValue = "IN", Name = "Indiana" },
            new SelectListItem() { ItemValue = "IA", Name = "Iowa" },
            new SelectListItem() { ItemValue = "KS", Name = "Kansas" },
            new SelectListItem() { ItemValue = "KY", Name = "Kentucky" },
            new SelectListItem() { ItemValue = "LA", Name = "Louisiana" },
            new SelectListItem() { ItemValue = "ME", Name = "Maine" },
            new SelectListItem() { ItemValue = "MD", Name = "Maryland" },
            new SelectListItem() { ItemValue = "MA", Name = "Massachusetts" },
            new SelectListItem() { ItemValue = "MI", Name = "Michigan" },
            new SelectListItem() { ItemValue = "MN", Name = "Minnesota" },
            new SelectListItem() { ItemValue = "MS", Name = "Mississippi" },
            new SelectListItem() { ItemValue = "MO", Name = "Missouri" },
            new SelectListItem() { ItemValue = "MT", Name = "Montana" },
            new SelectListItem() { ItemValue = "NE", Name = "Nebraska" },
            new SelectListItem() { ItemValue = "NV", Name = "Nevada" },
            new SelectListItem() { ItemValue = "NH", Name = "New Hampshire" },
            new SelectListItem() { ItemValue = "NJ", Name = "New Jersey" },
            new SelectListItem() { ItemValue = "NM", Name = "New Mexico" },
            new SelectListItem() { ItemValue = "NY", Name = "New York" },
            new SelectListItem() { ItemValue = "NC", Name = "North Carolina"},
            new SelectListItem() { ItemValue = "ND", Name = "North Dakota"},
            new SelectListItem() { ItemValue = "OH", Name = "Ohio" },
            new SelectListItem() { ItemValue = "OK", Name = "Oklahoma" },
            new SelectListItem() { ItemValue = "OR", Name = "Oregon" },
            new SelectListItem() { ItemValue = "PA", Name = "Pennsylvania" },
            new SelectListItem() { ItemValue = "RI", Name = "Rhode Island" },
            new SelectListItem() { ItemValue = "SC", Name = "South Carolina" },
            new SelectListItem() { ItemValue = "SD", Name = "South Dakota" },
            new SelectListItem() { ItemValue = "TN", Name = "Tennessee" },
            new SelectListItem() { ItemValue = "TX", Name = "Texas" },
            new SelectListItem() { ItemValue = "UT", Name = "Utah" },
            new SelectListItem() { ItemValue = "VT", Name = "Vermont" },
            new SelectListItem() { ItemValue = "VA", Name = "Virginia" },
            new SelectListItem() { ItemValue = "WA", Name = "Washington" },
            new SelectListItem() { ItemValue = "WV", Name = "West Virginia" },
            new SelectListItem() { ItemValue = "WI", Name = "Wisconsin" },
            new SelectListItem() { ItemValue = "WY", Name = "Wyoming" }
        };

        return states;
    }


Countries, and states within them come and go more frequently than you'd think around the world, and so hard coding them is not the best idea. It's best to get them both dynamically. Otherwise you're going to have to update your program every time there's a political change anywhere in the world. Further, from a software design perspective, political boundaries are data sets of significant size, and therefore putting them in a database instead of in your code should be the default choice.

If you can't pull from a web location, you should still be able to setup your code so that the data is stored somewhat-separately and pulled in dynamically it's therefore easier to update from a list.

There are ISO Standards for both, ISO_3166-1 for countries and ISO_3166-2 for country's administrative subdivisions (states/provinces), however they charge for ongoing access to their lists. There's also geonames.org which is free and what I'd therefore recommend to start with. Ideally you'll want a database which regularly updates from one of these sources, and then pull in the information from there.

There is a programmatic work-around for countries as in this SO answer: List of All Countries DropDown. However you'll notice that Regions do not map perfectly to countries, and therefore you'll have non-country regions like "Carribbean" in your results.


Here is the simple Java Map version of the USA and Canada, adapted from the other answers here.

  // the US State and Canada abbreviation dictionary, abbreviation --> full name
  private final static Map<String, String>     stateAbbreviationDictionary = new HashMap<>();

  static {
    // USA
    stateAbbreviationDictionary.put("AL", "Alabama");
    stateAbbreviationDictionary.put("AK", "Alaska");
    stateAbbreviationDictionary.put("AZ", "Arizona");
    stateAbbreviationDictionary.put("AR", "Arkansas");
    stateAbbreviationDictionary.put("CA", "California");
    stateAbbreviationDictionary.put("CO", "Colorado");
    stateAbbreviationDictionary.put("CT", "Connecticut");
    stateAbbreviationDictionary.put("DE", "Delaware");
    stateAbbreviationDictionary.put("DC", "District Of Columbia");
    stateAbbreviationDictionary.put("FL", "Florida");
    stateAbbreviationDictionary.put("GA", "Georgia");
    stateAbbreviationDictionary.put("HI", "Hawaii");
    stateAbbreviationDictionary.put("ID", "Idaho");
    stateAbbreviationDictionary.put("IL", "Illinois");
    stateAbbreviationDictionary.put("IN", "Indiana");
    stateAbbreviationDictionary.put("IA", "Iowa");
    stateAbbreviationDictionary.put("KS", "Kansas");
    stateAbbreviationDictionary.put("KY", "Kentucky");
    stateAbbreviationDictionary.put("LA", "Louisiana");
    stateAbbreviationDictionary.put("ME", "Maine");
    stateAbbreviationDictionary.put("MD", "Maryland");
    stateAbbreviationDictionary.put("MA", "Massachusetts");
    stateAbbreviationDictionary.put("MI", "Michigan");
    stateAbbreviationDictionary.put("MN", "Minnesota");
    stateAbbreviationDictionary.put("MS", "Mississippi");
    stateAbbreviationDictionary.put("MO", "Missouri");
    stateAbbreviationDictionary.put("MT", "Montana");
    stateAbbreviationDictionary.put("NE", "Nebraska");
    stateAbbreviationDictionary.put("NV", "Nevada");
    stateAbbreviationDictionary.put("NH", "New Hampshire");
    stateAbbreviationDictionary.put("NJ", "New Jersey");
    stateAbbreviationDictionary.put("NM", "New Mexico");
    stateAbbreviationDictionary.put("NY", "New York");
    stateAbbreviationDictionary.put("NC", "North Carolina");
    stateAbbreviationDictionary.put("ND", "North Dakota");
    stateAbbreviationDictionary.put("OH", "Ohio");
    stateAbbreviationDictionary.put("OK", "Oklahoma");
    stateAbbreviationDictionary.put("OR", "Oregon");
    stateAbbreviationDictionary.put("PA", "Pennsylvania");
    stateAbbreviationDictionary.put("RI", "Rhode Island");
    stateAbbreviationDictionary.put("SC", "South Carolina");
    stateAbbreviationDictionary.put("SD", "South Dakota");
    stateAbbreviationDictionary.put("TN", "Tennessee");
    stateAbbreviationDictionary.put("TX", "Texas");
    stateAbbreviationDictionary.put("UT", "Utah");
    stateAbbreviationDictionary.put("VT", "Vermont");
    stateAbbreviationDictionary.put("VA", "Virginia");
    stateAbbreviationDictionary.put("WA", "Washington");
    stateAbbreviationDictionary.put("WV", "West Virginia");
    stateAbbreviationDictionary.put("WI", "Wisconsin");
    stateAbbreviationDictionary.put("WY", "Wyoming");
    // Canada
    stateAbbreviationDictionary.put("AB", "Alberta");
    stateAbbreviationDictionary.put("BC", "British Columbia");
    stateAbbreviationDictionary.put("MB", "Manitoba");
    stateAbbreviationDictionary.put("NB", "New Brunswick");
    stateAbbreviationDictionary.put("NL", "Newfoundland and Labrador");
    stateAbbreviationDictionary.put("NS", "Nova Scotia");
    stateAbbreviationDictionary.put("NT", "Northwest Territories");
    stateAbbreviationDictionary.put("NU", "Nunavut");
    stateAbbreviationDictionary.put("ON", "Ontario");
    stateAbbreviationDictionary.put("PE", "Prince Edward Island");
    stateAbbreviationDictionary.put("QC", "Quebec");
    stateAbbreviationDictionary.put("SK", "Saskatchewan");
    stateAbbreviationDictionary.put("YT", "Yukon");
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜