标准化美国各州阵列和阵列的国家

标准化美国各州阵列和阵列的国家

本文介绍了标准化美国各州阵列和阵列的国家的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道一个好的,可用类的,每个人都在这里可以从为国家和State字段在窗体上填充组合框控件使用?受益

Does anyone know of a nice, usable class that 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!

我目前正在开发该Windows窗体(非Web应用程序),而这个项目不能从网站拉。

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

推荐答案

OK,所以我做了一个。

OK, so I made one.

我建立了它很好的和通用的,所以任何人都应该能够使用它

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

有在所谓的底部 US_States 被用作一个容器来存储国名和国家缩写的一类。

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);
  }

}

这篇关于标准化美国各州阵列和阵列的国家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 06:42