4AspNet IPInfo v1.0

IPInfo.GetInfoByCountryCode Method 

Retrieves country information by a country code.

public CountryInfo GetInfoByCountryCode(
   string countryCode
);

Parameters

countryCode
The string of two or three letters containing country code.

Return Value

The CountryInfo structure.

Remarks

Method GetInfoByCountryCode is useful when you know the country code and want to get more information about a country with that code.

It is possible to specify either two or three letters code as an argument. Also the method is case-insensitive, i.e. you may specify code in upper case, lower case or even in mixed case. For example passing any of these arguments "US", "USA", "us", "uSa" will return CountryInfo for United States.

When country information for the specified code is absent and ThrowIfNotFound property is set to false method will return CountryInfo structure without significant information. If ThrowIfNotFound is set to true, the exception of type CountryInfoNotFoundException will be thrown.

Exceptions

Exception TypeCondition
ArgumentNullExceptionThrown when specified argument is a null reference (Nothing in Visual Basic).
ArgumentExceptionThrown when specified argument contains less than two or more than three letters.
CountryInfoNotFoundExceptionThrown when property ThrowIfNotFound is set to true and there is no country information with a specified code.

Example

See example for ThrowIfNotFound property.

See Also

IPInfo Class | ForAspNet.IPInfo Namespace