当前位置: 首页>>代码示例>>C#>>正文


C# Country.Clone方法代码示例

本文整理汇总了C#中Country.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Country.Clone方法的具体用法?C# Country.Clone怎么用?C# Country.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Country的用法示例。


在下文中一共展示了Country.Clone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        private static void Main()
        {
            Country bg = new Country("Bulgaria", 7100000, 111000, new List<string> { "Sofia", "Plovdiv", "Varna" });
            Country usa = new Country(
                "USA",
                300000000,
                1200000,
                new List<string> { "New York", "Los Angeles", "San Francisco" });
            Country bg2 = new Country("Bulgaria", 8000000, 10);
            Country bg3 = new Country("Bulgaria", 8000000, 111000);
            Country hr = new Country("Croatia", 8000000, 111000);

            Console.WriteLine(bg == bg2);
            Console.WriteLine(bg == usa);
            Console.WriteLine(bg != bg2);
            Console.WriteLine(bg != usa);

            var countries = new List<Country> { bg, usa, bg2, bg3, hr };
            countries.Sort();

            Console.WriteLine(
                string.Join(Environment.NewLine, countries.Select(c => new { c.Name, c.Area, c.Population })));

            var bgCopy = bg.Clone() as Country;
            bg.Cities.Add("Kaspichan");
            Console.WriteLine(string.Join(", ", bg.Cities));
            Console.WriteLine(string.Join(", ", bgCopy.Cities));
        }
开发者ID:bulgariamitko,项目名称:SoftUniHomeWordsAndMore,代码行数:28,代码来源:Program.cs

示例2: Main

        public static void Main()
        {
            Country bg = new Country("Bulgaria", 7100000, 111000, new HashSet<string> { "Sofia", "Plovdiv", "Varna" });
            Country usa = new Country("USA", 300000000, 1200000, new HashSet<string> { "New York", "Los Angeles", "San Francisco" });
            Country bg2 = new Country("Bulgaria", 8000000, 10);
            Country bg3 = new Country("Bulgaria", 8000000, 111000);
            Country hr = new Country("Croatia", 8000000, 111000);

            // cloning coutries
            var bgCopy = bg.Clone() as Country;
            bg.Cities.Add("Kaspichan");

            Console.WriteLine("bg cities: {0}", string.Join(", ", bg.Cities));
            Console.WriteLine("bgCopy cities: {0}", string.Join(", ", bgCopy.Cities));

            // comparing HashCodes
            Console.WriteLine("bg.GetHashCode() = {0}", bg.GetHashCode());
            Console.WriteLine("bg2.GetHashCode() = {0}", bg2.GetHashCode());

            // comparing countries
            Console.WriteLine("bg.CompareTo(bgCopy): {0}", bg.CompareTo(bgCopy));
            Console.WriteLine("bg.CompareTo(usa): {0}", bg.CompareTo(usa));

            Console.WriteLine(bg.Equals(bg2));
            Console.WriteLine(Country.Equals(hr, bg));
            Console.WriteLine(bg == bg2); // True
            Console.WriteLine(bg == usa); // False
            Console.WriteLine(bg != bg2); // False
            Console.WriteLine(bg != usa); // True

            // sorting coutries
            var countries = new List<Country> { bg, usa, bg2, bg3, hr };
            countries.Sort();

            Console.WriteLine(
                string.Join(Environment.NewLine, countries
                    .Select(c => new { c.Name, c.Area, c.Population })));

            Console.WriteLine(string.Join(Environment.NewLine, countries));
        }
开发者ID:KatyaMarincheva,项目名称:Object-Oriented-Programming-Course,代码行数:40,代码来源:CountryMain.cs

示例3: Main

    public static void Main()
    {
        try
        {
            Country bg = new Country("Bulgaria", 7100000, 111000, "Sofia", "Plovdiv", "Varna");
            Country usa = new Country("USA", 300000000, 1200000, "New York", "Los Angeles", "San Francisco");
            Country bg2 = new Country("Bulgaria", 8000000, 10);
            Country bg3 = new Country("Bulgaria", 8000000, 111000);
            Country hr = new Country("Croatia", 8000000, 111000);

            Console.WriteLine(bg == bg2); // True
            Console.WriteLine(bg == usa); // False
            Console.WriteLine(bg != bg2); // False
            Console.WriteLine(bg != usa); // True

            var countries = new List<Country> { bg, usa, bg2, bg3, hr };
            countries.Sort();

            Console.WriteLine(
                string.Join(Environment.NewLine, countries
                    .Select(c => new {c.Name, c.Area, c.Population})));

            var bgCopy = bg.Clone() as Country;
            bg.Cities.Add("Kaspichan");
            Console.WriteLine(string.Join(", ", bg.Cities));
            Console.WriteLine(string.Join(", ", bgCopy.Cities));

        }

        catch (ArgumentNullException ex)
        {
            Console.Error.WriteLine(ex.Message);
        }

        catch (ArgumentOutOfRangeException ex)
        {
            Console.Error.WriteLine(ex.Message);
        }
    }
开发者ID:onefen,项目名称:Exersize-CommonTypeSysterm,代码行数:39,代码来源:MainProgram.cs


注:本文中的Country.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。