Domanda

I am trying to convert this AddressParser (http://usaddress.codeplex.com/) from .Net 4.0 to .Net 3.5 and I'm running into a small problem.

I get a cannot convert from 'System.Collections.Generic.Dictionary<string,string>.KeyCollection' to 'string[]' error on the commented line below. It specifically underlines rangelessSecondaryUnits.Keys

Any help converting this would be wonderful!

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";
È stato utile?

Soluzione

remove one of your string.Join

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

Your error, besides the ToArray is that in .NET3.5 there's no overload that takes a params string[]. But, your outer string.join was doing nothing, because your inner string.Join was returning the one string.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top