Zip2City 3.0.0

.NET 5.0 .NET Core 3.1 .NET Standard 2.1 .NET Framework 4.0
Install-Package Zip2City -Version 3.0.0
dotnet add package Zip2City --version 3.0.0
<PackageReference Include="Zip2City" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Zip2City --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Zip2City, 3.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Zip2City as a Cake Addin
#addin nuget:?package=Zip2City&version=3.0.0

// Install Zip2City as a Cake Tool
#tool nuget:?package=Zip2City&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Provides fast, in-memory lookup of the postal service city/state names by zip code. All 50 states, DC, PR, VI, and AE. Data current as of September 28, 2021. No external library dependencies. No external calls.

  • Light-weight (430KB)
  • No external library dependencies
  • No external calls

.GetDefaultCityState(zipcode)

var zipcode = "90210";
var cityAndState = Zip2City.GetDefaultCityState(zipcode);  // returns null when there's no match

var city = cityAndState[0];  // "BEVERLY HILLS"
var state = cityAndState[1];  // "CA"

.GetAllCityStates(zipcode)

var zipcode = "37411";
var citysAndStates = Zip2City.GetAllCityStates(zipcode).ToArray();  // returns IEnumerable<string[]> regardless of whether there is a match

var defaultCity = citysAndStates[0];  // "CHATTANOOGA"
var defaultState = citysAndStates[0][1];  // "TN"
var city2 = citysAndStates[1][0];  // "RIDGESIDE"
var state2 = citysAndStates[1][1];  // "TN"

.GetClosestCityState(zipcode)

var zipcode = "99999";
var cityAndState = Zip2City.GetClosestCityState(zipcode);

var city = cityAndState[0];  // "KETCHIKAN"
var state = cityAndState[1];  // "AK"

.GetClosestCityStates(zipcode)

var zipcode = "37411";
var citysAndStates = Zip2City.GetClosestCityStates(zipcode).ToArray();

var defaultCity = citysAndStates[0];  // "KETCHIKAN"
var defaultState = citysAndStates[0][1];  // "AK"
var city2 = citysAndStates[1][0];  // "EDNA BAY"
var state2 = citysAndStates[1][1];  // "AK"
var city3 = citysAndStates[2][0];  // "KASAAN"
var state3 = citysAndStates[2][1];  // "AK"

.GetRandomCityStateZip()

var randomCityStateZip = Zip2City.GetRandomCityStateZip();  // always returns a valid set of city, state, and zip code.

var city = cityAndState[0];  // "TROY"
var state = cityAndState[1];  // "TX"
var zipcode = cityAndState[1];  // "76579"

.GetRandomCityStateZip(random)

var random = new Random(12345);  // seeding will guarantee the return values
var randomCityStateZip = Zip2City.GetRandomCityStateZip(random);

var city = cityAndState[0];  // "ALBANY"
var state = cityAndState[1];  // "GA"
var zipcode = cityAndState[1];  // "31707"

.AllCityStateZips

var allData = Zip2City.AllCityStateZips
var californiaData = allData.Where(d => d[1] == "CA").ToArray()
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
.NET Framework net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 798 3/12/2022
2.1.0 1,804 10/9/2021
2.0.0 235 10/7/2021
1.0.3 3,367 10/18/2020

3.0.0
* (BREAKING CHANGE) Ended .NET 2.0 support
* (BREAKING CHANGE) Introduced namespace
* Added .GetClosestCityState(zipcode) and .GetClosestCityStates(zipcode) for the exact or the closest match
* Optimized .GetRandomCityStateZip() implementation
* Added .GetRandomCityStateZip(random) for predictable values
* Added static property to get all data
* Added .NET 6 support