New paste Repaste Download
using System;
using System.Collections.Generic;
public class City
{
    private string _name;
    private string _country;
    private int _population;
    private string _phoneCode;
    private List<string> _districts;
    public City(string name = null, string country = null, int population = 0, string phoneCode = null, List<string> districts = null)
    {
        _name = name;
        _country = country;
        _population = population;
        _phoneCode = phoneCode;
        _districts = districts ?? new List<string>();
    }
    public string Name
    {
        get { return _name ?? "None"; }
        set { _name = value; }
    }
    public string Country
    {
        get { return _country; }
        set { _country = value; }
    }
    public int Population
    {
        get { return Math.Max(0, _population); }
        set { _population = value < 0 ? 0 : value; }
    }
    public string PhoneCode
    {
        get { return _phoneCode; }
        set { _phoneCode = value; }
    }
    public List<string> Districts
    {
        get { return _districts; }
        set { _districts = value; }
    }
}
class Program
{
    static void Main()
    {
        City city1 = new City("New York", "USA", -10000, "+1", new List<string> { "Manhattan", "Brooklyn" });
        Console.WriteLine(city1.Name);        // Выведет "New York"
        Console.WriteLine(city1.Country);     // Выведет "USA"
        Console.WriteLine(city1.Population);  // Выведет 0
        Console.WriteLine(city1.PhoneCode);   // Выведет "+1"
        foreach (var district in city1.Districts)
        {
            Console.WriteLine(district);      // Выведет "Manhattan" и "Brooklyn"
        }
    }
}
Filename: None. Size: 2kb. View raw, , hex, or download this file.

This paste expires on 2024-04-30 09:01:39.879021. Pasted through web.