我创建了以下内容,以将某些数据作为正则表达式匹配字符串以及StringDictionary公开。感觉我可以用更少的行使用LINQ来做到这一点。
private const string STREETTYPES = @"ALY|Alley|AVE|Avenue|BLVD|Boulevard|CIR|Circle|CT|Court|CTR|Center|DR|Drive|EXPY|Expressway|FWY|Freeway|HALL|Hall|HWY|Highway|JCT|Junction|LN|Lane|LP|Loop|PIKE|Pike|PKWY|Parkway|PL|Place|RD|Road|ST|Street|TER|Terrace|TPKE|Turnpike|TRL|Trail|WAY|Way";
private static StringDictionary streetTypes = null;
public static StringDictionary StreetTypes
{
get
{
if (streetTypes != null) return streetTypes;
streetTypes = new StringDictionary();
var streetArray = STREETTYPES.Split(PIPE);
for (int i = 0; i < streetArray.Length-1; i = i+2)
{
streetTypes.Add(streetArray[i], streetArray[i + 1]);
}
return streetTypes;
}
}
最佳答案
怎么样:
private static readonly StringDictionary streetTypes = new StringDictionary
{
{"ALY","Alley"},{"AVE","Avenue"},{"ALY","Alley"},{"BLVD","Boulevard"},{"CIR","Circle"},
{"CT","Court"},{"CTR","Center"},{"DR","Drive"},{"EXPY","Expressway"},{"FWY","Freeway"},
{"HALL","Hall"},{"HWY","Highway"},{"JCT","Junction"},{"LN","Lane"},{"LP","Loop"},
...
};