Skip to content

Instantly share code, notes, and snippets.

@sadache
Created December 5, 2009 16:48
Show Gist options
  • Save sadache/249757 to your computer and use it in GitHub Desktop.
Save sadache/249757 to your computer and use it in GitHub Desktop.
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