本文整理汇总了C#中Customer.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Customer.CompareTo方法的具体用法?C# Customer.CompareTo怎么用?C# Customer.CompareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Customer
的用法示例。
在下文中一共展示了Customer.CompareTo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
List<Payment> payments = new List<Payment>
{
new Payment("Payyy", "10 lv."),
new Payment("Payyy2", "210 lv."),
};
//check 2 payments with Equals and ==
//Payment p1 = new Payment("Payyy", "10 lv.");
//Payment p2 = new Payment("Payyy", "10 lv.");
//Console.WriteLine(p1.Equals(p2));
//Console.WriteLine(p1 == p2);
//Console.WriteLine("=================================");
//Check 2 customer, one a clone of the other, with Equals and ==
Customer a = new Customer("Pesho", "Ivanov", "Petrov", 1111, "Severna Koreq", "08898967674", "[email protected]", payments, CustomerType.Golden);
//Customer b = new Customer("Pesho", "Ivanov", "Petrov", 1111, "Severna Koreq", "08898967674", "[email protected]", payments, CustomerType.Golden);
Customer b = a.Clone() as Customer;
Customer c = a;
Console.WriteLine(a.Equals(b)); //da
Console.WriteLine(a.Equals(c)); //da
Console.WriteLine(a == b); //ne
c.FirstName = "blq";
Console.WriteLine(a == c); //da
//CompareTo
a.FirstName = "Pesho";
Console.WriteLine(a.CompareTo((Customer)b)); //0
b.FirstName = "Todor";
Console.WriteLine(a.CompareTo((Customer)b)); //Pesho > Todor
}
示例2: Main
static void Main()
{
Customer lili = new Customer(
"Lili",
"Kalapova",
"Bonin",
1234567,
"Plovdiv",
"4567456",
"[email protected]",
new List<Payment>() { new Payment("Lenovo laptop", 850) },
CustomerType.OneTime);
Customer gosho = new Customer(
"Gosho",
"Kostadinov",
"Kalapov",
9876543,
"Luisville",
"09017654",
"[email protected]",
new List<Payment>() { new Payment("Calculator", 50), new Payment("Mouse Pad", 13), new Payment("Mic", 6) },
CustomerType.Regular);
Customer emo = new Customer(
"Emil",
"Georgiev",
"Georgiev",
5454590,
"Sofia",
"08983334",
"[email protected]",
new List<Payment>() { new Payment("Server", 2850) },
CustomerType.Golden);
var liliCopy = lili;
lili.Payments.Add(new Payment("mouse", 12));
lili.LastName = "kalapova-bonin";
Console.WriteLine(lili);
Console.WriteLine(liliCopy);
Console.WriteLine(liliCopy == lili);
Console.WriteLine(lili.Equals(liliCopy));
var liliClone = (Customer)lili.Clone();
Console.WriteLine(lili == gosho);
Console.WriteLine(lili == liliClone);
Console.WriteLine(lili == liliCopy);
Console.WriteLine(lili.CompareTo(gosho));
Console.WriteLine(emo.CompareTo(lili));
Console.WriteLine(lili.CompareTo(liliClone));
}
示例3: Main
public static void Main()
{
List<Payment> payments = new List<Payment>()
{
new Payment("product1", 55.93),
new Payment("product2", 103.37)
};
Customer customer = new Customer(
"Peshkz",
"Goshkov",
"Ivanov",
9112162821,
"Adres",
"[email protected]",
"0888888888",
payments,
CustomerType.Golden);
Customer customer2 = new Customer(
"Peshko",
"Goshkov",
"Ivanov",
9112162820,
"Adres",
"[email protected]",
"0888888888",
payments,
CustomerType.Golden);
Console.WriteLine(customer.CompareTo(customer2));
}
示例4: 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));
}
示例5: Main
static void Main()
{
var pesho = new Customer("Petar", "Ivanov", "Mitrev", "123456789","dolno tunkovo", "123123123","[email protected]");
var pesho2 = new Customer("Petar", "Ivanov", "Mitrev", "123456788","dolno tunkovo","123123123123", "[email protected]");
var gosho = new Customer("Gosho", "Ivanov", "Shopov", "100000001","na maikasi putkata","1-500-123123","[email protected]");
Payment[] payments =
{
new Payment("book", 25.5m),
new Payment("phone", 250.89m),
new Payment("tablet", 500),
new Payment("phone", 250.89m),
new Payment("tablet", 500)
};
foreach (var payment in payments)
{
pesho.AddPayment(payment);
gosho.AddPayment(payment);
}
var petarCloning = (Customer)pesho.Clone();
//Console.WriteLine(gosho);
Console.WriteLine(pesho == gosho);
Console.WriteLine(pesho == pesho2);
Console.WriteLine(pesho == petarCloning);
Console.WriteLine(pesho.CompareTo(gosho));
Console.WriteLine(pesho2.CompareTo(pesho));
Console.WriteLine(pesho.CompareTo(petarCloning));
Console.WriteLine("=------------------------------------------");
Customer cloning = (Customer)pesho.Clone();
pesho.Payments[0].ProductPrice = 200;
cloning.Payments[0].ProductPrice = 100000;
Console.WriteLine("Pesho cloninig:\n{0}", cloning.Payments[0].ProductPrice);
Console.WriteLine("Pesho:\n{0}", pesho.Payments[0].ProductPrice);
}
示例6: Main
public static void Main()
{
Customer rado = new Customer("Rado", "Radov", "Radov", 9043367759, "Radovo", "0888696969", "[email protected]", CustomerType.Golden, new List<Payment>());
Customer radoCloned = (Customer) rado.Clone();
Console.WriteLine(rado.Equals(radoCloned)); // Should be true
radoCloned.Id = 4356345563;
radoCloned.Payments.Add(new Payment("ProductName", 43543643));
Console.WriteLine(rado.Equals(radoCloned)); // Should be false
Console.WriteLine(rado.CompareTo(radoCloned) > 0); // The name is the same but the ID of rado > of ID radoCloned
}
示例7: 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!");
}
}