Get a country's continent in C#

Nothing like that in the .NET framework. It is also rather ambiguous with geographical definitions for Eurasia and Oceania. There are 6 distinct definitions in use. You'll need your own dbase.


You can store a hash table. The entries will have as key the country name and as value the continent name. Just generate this table from some public database and once you have it you can simply query it. It's also pretty fast.

http://www.geonames.org/countries/
You can get from there a database (there is an option to Download/Export)


There are only a few continents and only a couple of hundred countries, so it wouldn't be very hard just to build your own table. There are differences of opinion as to just what the continents are (Australia/Oceania/Australasia/Asia being a particularly prickly one at times), and whether e.g. Turkey and Russia are in Europe, Asia, or both. Still, rolling your own at least lets you make your own call on these matters.