-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompareCustomer.cs
75 lines (70 loc) · 2.03 KB
/
CompareCustomer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
namespace Testing
{
class CompareCustomer :IComparable
{
private string name;
private string address;
private double balance;
public string Name
{
get
{
return name;
}
}
public string Address
{
get
{
return address;
}
}
public double Balance
{
get
{
return balance;
}
}
public CompareCustomer(string n, string a, double b)
{
name = n;
address = a;
balance = b;
}
public int CompareTo(Object obj2){
if (obj2 is CompareCustomer)
{
CompareCustomer c2 = (CompareCustomer)obj2;
return name.CompareTo(c2.name);
}
else
{
return -1;
}
}
}
class MainClass
{
public static void Main(string[] args)
{
CompareCustomer c = new CompareCustomer("Tan Ah Lian", "4 Short Street", 2000);
CompareCustomer d = new CompareCustomer("Tan Ah Kow", "81 Berry Road", 1500);
int n = 65;
int m = 231;
int[] intArray = new int[] { 90, 20, 24, 10, 80 };
foreach (int x in intArray) Console.Write("{0} ", x); Console.WriteLine();
Array.Sort(intArray);
foreach (int x in intArray) Console.Write("{0} ", x); Console.WriteLine();
Console.WriteLine(n < m);
Console.WriteLine(c.CompareTo(d));
CompareCustomer[] customerArray = new CompareCustomer[] { new CompareCustomer("Tan Ah L", "4 Short Street", 2000), new CompareCustomer("Tan Ah Kow", "81 Berry Road", 1500) };
Array.Sort(customerArray);
foreach (CompareCustomer x in customerArray)
{
Console.WriteLine("{0} ", x.Name);
}
}
}
}