将Dictionary <string,string> .KeyCollection转换为string [] .Net 3.5 </string,string>

时间:2014-04-24 16:31:47

标签: c# .net-4.0 .net-3.5

我正在尝试将此AddressParser(http://usaddress.codeplex.com/)从.Net 4.0转换为.Net 3.5,我遇到了一个小问题。

我在下面的注释行中收到cannot convert from 'System.Collections.Generic.Dictionary<string,string>.KeyCollection' to 'string[]'错误。它特别强调rangelessSecondaryUnits.Keys

任何帮助转换它都会很精彩!

private static Dictionary<string, string> rangelessSecondaryUnits =
            new Dictionary<string, string>()
            {
                { "BA?SE?ME?N?T", "BSMT" },
                { "FRO?NT", "FRNT" },
                { "LO?BBY", "LBBY" },
                { "LOWE?R", "LOWR" },
                { "OFF?I?CE?", "OFC" },
                { "PE?N?T?HO?U?S?E?", "PH" },
                { "REAR", "REAR" },
                { "SIDE", "SIDE" },
                { "UPPE?R", "UPPR" }
            };

var rangelessSecondaryUnitPattern =
                @"(?<SECONDARYUNIT>" +
                string.Join(
                    "|",
                    string.Join("|", rangelessSecondaryUnits.Keys)) + //ERROR ON THIS LINE
                @")\b";

1 个答案:

答案 0 :(得分:1)

删除您的string.Join

之一
var rangelessSecondaryUnitPattern =
        @"(?<SECONDARYUNIT>" +
        string.Join("|", rangelessSecondaryUnits.Keys.ToArray()) +
        @")\b";

ToArray之外,您的错误是在.NET3.5中没有超载需要params string[]。但是,你的外部string.join什么也没做,因为你的内部string.Join正在返回一个字符串。