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


C# Customer.GetHashCode方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            List<Payment> payments = new List<Payment>()
            {
                new Payment("Laptop", 999),
                new Payment("Glasses", 300),
                new Payment("Vodka", 60)
            }; 

            Customer pesho = new Customer("Pesho", "Peshev", "Peshov", "6840562897",
                "Karlukovo", "+3598888888888", "[email protected]", payments, CustomerType.Golden);

            Customer gosho = new Customer("Gosho", "Georgiev", "Goshev", "5068795469", 
                "Gorna Orqhovica", "+359878967458", "[email protected]", payments, CustomerType.Diamond);

            Console.WriteLine(pesho.CompareTo(gosho));
            Console.WriteLine(pesho.Equals(gosho));
            
            Console.WriteLine();
            Console.WriteLine(pesho);
            Console.WriteLine(pesho.GetHashCode());

            object clonedCustomer = gosho.Clone();
            Console.WriteLine(clonedCustomer.Equals(gosho));


        }
开发者ID:premiera85,项目名称:Software-University,代码行数:27,代码来源:TestCustomers.cs

示例2: TestClone

        public void TestClone()
        {
            var customer = new Customer();
            var clone = customer.Clone();

            Assert.IsFalse(customer == clone);
            Assert.AreNotSame(customer, clone);
            Assert.AreEqual(customer, clone);
            Assert.IsTrue(customer.Equals(clone));
            Assert.AreEqual(customer.GetHashCode(), clone.GetHashCode());
            Assert.IsInstanceOf<Customer>(clone);
            Assert.AreEqual(customer.Id, ((IPersistentObject)clone).Id);
        }
开发者ID:eithery,项目名称:core,代码行数:13,代码来源:PersistentObjectTest.cs

示例3: Main

        public static void Main()
        {
            try
            {
                Payment payment1 = new Payment("Pechka", 100m);
                Payment payment2 = new Payment("Televizor", 1000m);

                List<Payment> peshoPaiments = new List<Payment>
                {
                    payment1,
                    payment2
                };

                Customer pesho = new Customer("Pesho", "Peshev", "Dimirov", 8510019001, "Pod mosta", "None", "None",
                    peshoPaiments, CustomerType.OneTime);

                Payment payment3 = new Payment("Vibrator", 15m);
                Payment payment4 = new Payment("Prashki", 5m);

                List<Payment> mariikaPayments = new List<Payment>
                {
                    payment3,
                    payment4
                };

                Customer mariika = new Customer("Mariika", "NaBatkoKuklata", "Obstata", 9501017805, "tam niakude",
                    "de da i znaeh telefona", "[email protected]", mariikaPayments, CustomerType.Diamond);

                Console.WriteLine("Client1: {0}\n \n Client2: {1}", pesho, mariika);

                Console.WriteLine();
                Console.WriteLine("Is Pesho equals to Mariika: {0}", pesho.Equals(mariika));
                Console.WriteLine("Is Pesho equals to Pesho: {0}", pesho.Equals(pesho));
                Console.WriteLine();
                Console.WriteLine("Pesho == Mariika?: {0}", pesho == mariika);
                Console.WriteLine("Pesho != Mariika?: {0}", pesho != mariika);

                Customer gosho = (Customer) pesho.Clone();
                Customer stela = (Customer) mariika.Clone();

                Console.WriteLine();
                Console.WriteLine("Cloned client: {0}", gosho);
                Console.WriteLine();
                Console.WriteLine("Is Pesho equals to Gosho: {0}", pesho.Equals(gosho));

                gosho.FirstName = "Gosho";
                gosho.MiddleName = "Stefanov";
                gosho.LastName = "Goshev";

                Console.WriteLine();
                Console.WriteLine("Cloned client1 after changes: {0}", gosho);
                Console.WriteLine();
                Console.WriteLine("Is Pesho equals to Gosho: {0}", pesho.Equals(gosho));
                Console.WriteLine();

                stela.FirstName = "Stela";
                stela.MiddleName = "Ivanova";
                stela.LastName = "Petkova";

                Console.WriteLine();
                Console.WriteLine("Cloned client2 after changes: {0}", stela);
                Console.WriteLine();
                Console.WriteLine("Is Mariika equals to Stela: {0}", mariika.Equals(stela));
                Console.WriteLine();

                Console.WriteLine("Mariika's Hash Code: {0}", mariika.GetHashCode());
                Console.WriteLine("Pesho's Hash Code: {0}", pesho.GetHashCode());
            }

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

            catch (ArgumentOutOfRangeException ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
开发者ID:onefen,项目名称:Homework_CommonTypeSystem,代码行数:79,代码来源:MainCustomerProgram.cs

示例4: Test_StructuralTuple


//.........这里部分代码省略.........
                        Id       = 100L         ,
                        Address1 = "My street"  ,
                        Zip      = "000HOME"    ,
                        City     = "My hometown",
                        Country  = "The Motherland"
                    },
                DeliveryAddress =
                    new Address
                    {
                        Id       = 101L                 ,
                        CareOf   = "My mom"             ,
                        Address1 = "My mom's street"    ,
                        Zip      = "001HOME"            ,
                        City     = "My mom's hometown"  ,
                        Country  = "The Motherland"
                    }

            };

            var three = new Customer
            {
                Id          = 10L           ,
                FirstName   = "A."          ,
                LastName    = "Tester"      ,
                Aliases     = new [] {"Another", "Any"},
                InvoiceAddress =
                    new Address
                    {
                        Id       = 200L         ,
                        Address1 = "My street"  ,
                        Zip      = "000HOME"    ,
                        City     = "My hometown",
                        Country  = "The Motherland"
                    },
                DeliveryAddress =
                    new Address
                    {
                        Id       = 201L                 ,
                        CareOf   = "My mom"             ,
                        Address1 = "My mom's street"    ,
                        Zip      = "001HOME"            ,
                        City     = "My mom's hometown"  ,
                        Country  = "The Motherland"
                    }

            };

            var four = new Customer
            {
                Id          = 20L           ,
                FirstName   = "A."          ,
                LastName    = "Tester"      ,
                Aliases     = new [] {"Another", "Any"},
                InvoiceAddress =
                    new Address
                    {
                        Id       = 200L         ,
                        Address1 = "My street"  ,
                        Zip      = "000HOME"    ,
                        City     = "My hometown",
                        Country  = "The Motherland"
                    },
                DeliveryAddress =
                    new Address
                    {
                        Id       = 201L                 ,
                        CareOf   = "My mom"             ,
                        Address1 = "My mom's street"    ,
                        Zip      = "001HOME"            ,
                        City     = "My mom's hometown"  ,
                        Country  = "The Motherland"
                    }

            };

            var asString = one.ToString ();
            TestFor.Equality (StructuralTupleAsString, asString, "Tuple.ToString must match");

            TestFor.Equality (true  , one.Equals(one)   , "Identical tuples must match");

            TestFor.Equality (true  , one.Equals(two)   , "Structural identical tuples must match");
            TestFor.Equality (true  , two.Equals(one)   , "Structural identical tuples must match");

            TestFor.Equality (false , one.Equals(three) , "Structural non-identical tuples must not match");
            TestFor.Equality (false , three.Equals(one) , "Structural non-identical tuples must not match");

            TestFor.Equality (false , one.Equals(four)  , "Structural non-identical tuples must not match");
            TestFor.Equality (false , four.Equals(one)  , "Structural non-identical tuples must not match");

            TestFor.Equality (true  , one.GetHashCode() == one.GetHashCode()    , "Identical tuples must have same hash code");

            TestFor.Equality (true  , one.GetHashCode() == two.GetHashCode()    , "Structural identical tuples must have same hash code");
            TestFor.Equality (true  , two.GetHashCode() == one.GetHashCode()    , "Structural identical tuples must have same hash code");

            TestFor.Equality (false , one.GetHashCode() == three.GetHashCode()  , "Structural non-identical tuples must not have same hash code");
            TestFor.Equality (false , three.GetHashCode() == one.GetHashCode()  , "Structural non-identical tuples must not have same hash code");

            TestFor.Equality (false , one.GetHashCode() == four.GetHashCode()   , "Structural non-identical tuples must not have same hash code");
            TestFor.Equality (false , four.GetHashCode() == one.GetHashCode()   , "Structural non-identical tuples must not have same hash code");
        }
开发者ID:mrange,项目名称:T4Include,代码行数:101,代码来源:TestsFor_NamedTuple.cs

示例5: Main

        static void Main()
        {
            string decorationLine = new string('-', Console.WindowWidth);
            Console.Write(decorationLine);
            Console.WriteLine("***Creating some customer objects and performing some operations over them***");
            Console.Write(decorationLine);

            // Creating the Customer
            Customer customer1 = new Customer(
                "Ivan",
                "Ivanov",
                "Ivanov",
                "5712036203",
                "Sofia, street: \"Street name\" #15",
                "0888888888",
                "[email protected]",
              new List<Payment>() { new Payment("VW Golf", 1000m) },
              CustomerType.Onetime
              );
            Customer customer2 = new Customer(
                "Georgi",
                "Georgiev",
                "Georgiev",
                "9003034466",
                "Sofia, street: \"Street name\" #199",
                "0887777777",
                "[email protected]",
              new List<Payment>() { new Payment("Brigstone", 800m) },
              CustomerType.Regular
              );

            Console.WriteLine("***Printing the information about two Customer***");
            // The ToString() method demonstration
            Console.WriteLine(customer1);
            Console.WriteLine(customer2);

            Console.WriteLine("***Comparing the Customer with Equals()***");
            Console.WriteLine("Result of comparison: " + customer1.Equals(customer2));
            Console.WriteLine();

            Console.WriteLine("***Testing the GetHashCode() method***");
            Console.WriteLine("First Customer's hash code: " + customer1.GetHashCode());
            Console.WriteLine("Second Customer's has code: " + customer2.GetHashCode());
            Console.WriteLine();

            Console.WriteLine("***Testing the operators '==' and '!='***");
            Console.WriteLine("first Customer == second Customer -> " + (customer1 == customer2));
            Console.WriteLine("first Customer != second Customer -> " + (customer1 != customer2));
            Console.WriteLine();

            Console.WriteLine("***Cloning the first Customer and printing the clone***");
            Customer cloneCustomer = customer1.Clone();
            Console.WriteLine("Result of comparison of cloneCustomer: " + customer1.Equals(cloneCustomer));
            Console.WriteLine(cloneCustomer);
            Console.WriteLine("***Changing original's address, clone's mobile phone  and new Payments and priniting both***");
            customer1.Address = "Sofia, street \"New street\" #111";
            cloneCustomer.MobilePhone = "0800000011";
            cloneCustomer.Type = CustomerType.Golden;
            cloneCustomer.Payments = new List<Payment>() { new Payment("eBook", 200m) };
            Console.WriteLine(customer1);
            Console.WriteLine(cloneCustomer);

            Console.WriteLine("***Comparing first Customer with second Customer by CompareTo() method***");
            if (customer1.CompareTo(customer2) == 0)
            {
                Console.WriteLine("Both Customer are equal!");
            }
            else if (customer1.CompareTo(customer2) < 0)
            {
                Console.WriteLine("The first Customer is before the second one!");
            }
            else
            {
                Console.WriteLine("The first Customer is after the second one!");
            }
        }
开发者ID:GeorgiLambov,项目名称:SoftwareUniversity,代码行数:76,代码来源:TestCustomer.cs

示例6: TestGetHashCode

        public void TestGetHashCode()
        {
            var customer = new Customer();
            var clone = customer.Clone();

            Assert.AreEqual(customer.Id.Value.GetHashCode() ^ typeof(Customer).GetHashCode(),
                customer.GetHashCode());
            Assert.AreEqual(customer.GetHashCode(), clone.GetHashCode());
            Assert.AreNotEqual(new Customer().GetHashCode(), customer.GetHashCode());
        }
开发者ID:eithery,项目名称:core,代码行数:10,代码来源:PersistentObjectTest.cs


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