lista de comarcas de cataluña in csharp

To list the regions/comarcas of Catalonia in C#, you can create a class that represents a region and populate a list of instances of that class with the appropriate data:

main.cs
public class Comarca
{
    public string Name { get; set; }
    public int Population { get; set; }
    public string Capital { get; set; }

    public Comarca(string name, int population, string capital)
    {
        Name = name;
        Population = population;
        Capital = capital;
    }
}

public class Catalonia
{
    public List<Comarca> Comarcas { get; set; }

    public Catalonia()
    {
        Comarcas = new List<Comarca>();

        // Add the regions/comarcas and their data
        Comarcas.Add(new Comarca("Alt Empordà", 130788, "Figueres"));
        Comarcas.Add(new Comarca("Baix Empordà", 127729, "La Bisbal d'Empordà"));
        Comarcas.Add(new Comarca("Garrotxa", 51966, "Olot"));
        //...
        Comarcas.Add(new Comarca("Vall d'Aran", 9837, "Viella"));
    }
}

// Usage example:
var catalonia = new Catalonia();
foreach (var comarca in catalonia.Comarcas)
{
    Console.WriteLine($"{comarca.Name}: capital {comarca.Capital}, population {comarca.Population}");
}
1000 chars
38 lines

This will output the following list:

main.cs
Alt Empordà: capital Figueres, population 130788
Baix Empordà: capital La Bisbal d'Empordà, population 127729
Garrotxa: capital Olot, population 51966
//...
Vall d'Aran: capital Viella, population 9837
202 chars
6 lines

gistlibby LogSnag