Created
December 5, 2009 16:48
-
-
Save sadache/249757 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static IDictionary<string,int> zipCodes= new Dictionary<string,int>{ | |
{"Paris",75} | |
}; | |
static IDictionary<int, int> population = new Dictionary<int, int>{ | |
{75,100} | |
}; | |
static int? GetInterstingNumber(string cityName){ | |
const int TOTAL_POPULATION=123; | |
int? myCityCode=null; | |
try | |
{ | |
myCityCode = zipCodes[cityName]; | |
} | |
catch(KeyNotFoundException e) | |
{ | |
myCityCode = null; | |
} | |
try | |
{ | |
return (population[myCityCode.Value] * 100 / TOTAL_POPULATION); | |
} | |
catch (KeyNotFoundException e) | |
{ | |
return null; | |
} | |
catch(/* .Value can produce a*/ InvalidOperationException e) | |
{ | |
return null; | |
} | |
} | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Homs has "+getInterstingNumber("Paris")+"% of France populatin"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment