create a enum of countries in africa in csharp

You can create an enum of African countries in C# by defining an enum type and listing out all the countries as named constants separated by commas. Here is an example:

main.cs
public enum AfricanCountry
{
    Algeria,
    Angola,
    Benin,
    Botswana,
    BurkinaFaso,
    Burundi,
    Cameroon,
    CapeVerde,
    CentralAfricanRepublic,
    Chad,
    Comoros,
    DemocraticRepublicOfCongo,
    RepublicOfTheCongo,
    CoteDIvoire,
    Djibouti,
    Egypt,
    EquatorialGuinea,
    Eritrea,
    Ethiopia,
    Gabon,
    Gambia,
    Ghana,
    Guinea,
    GuineaBissau,
    Kenya,
    Lesotho,
    Liberia,
    Libya,
    Madagascar,
    Malawi,
    Mali,
    Mauritania,
    Mauritius,
    Morocco,
    Mozambique,
    Namibia,
    Niger,
    Nigeria,
    Rwanda,
    SaoTomeAndPrincipe,
    Senegal,
    Seychelles,
    SierraLeone,
    Somalia,
    SouthAfrica,
    SouthSudan,
    Sudan,
    Swaziland,
    Tanzania,
    Togo,
    Tunisia,
    Uganda,
    Zambia,
    Zimbabwe
}
812 chars
58 lines

You can then use this enum type as a parameter or return value for functions that deal with African countries. For example:

main.cs
public void PrintAfricanCountry(AfricanCountry country)
{
    Console.WriteLine("You selected: " + country.ToString());
}

public AfricanCountry GetRandomAfricanCountry()
{
    Random random = new Random();
    AfricanCountry[] countries = (AfricanCountry[])Enum.GetValues(typeof(AfricanCountry));
    return countries[random.Next(countries.Length)];
}

// Usage
var country = AfricanCountry.SouthAfrica;
PrintAfricanCountry(country); // Output: You selected: SouthAfrica

var randomCountry = GetRandomAfricanCountry();
Console.WriteLine("Random African country: " + randomCountry.ToString());
594 chars
19 lines

gistlibby LogSnag