עליך להתחבר בכדי להוריד קבצים מהאתר
על מנת להבטיח שמשאבינו לא ינוצלו לרעה.
public Type PropertyName { get
}{ return var; } set { var= value; } |
1 : class Point
2 : {
3 : private int x;
4 : private int y;
5 : public Point()
6 : {
7 : }
8 : public Point(int x, int y)
9 : {
10 : this.X = x;
11 : this.Y = y;
12 : }
13 : public void Print()
14 : {
15 : Console.WriteLine("x = {0}, y = {1}", x, y);
16 : }
17 : public int X
18 : {
19 : get
20 : {
21 : return x;
22 : }
23 : set
24 : {
25 : if (value >= 0 && value < = 1200)
26 : x = value;
27 : }
28 : }
29 : public int Y
30 : {
31 : get
32 : {
33 : return y;
34 : }
35 : set
36 : {
37 : if (value >= 0 && value < = 600)
38 : y = value;
39 : }
40 : }
41 : }
1 : class Program
2 : {
3 : static void Main(string[] args)
4 : {
5 : Point p1 = new Point(11, 22);
6 : Point p2 = new Point(33, 44);
7 : if (p1.X == p2.X && p1.Y == p2.Y)
8 : {
9 : Console.WriteLine("P1 and P2 are equals");
10 : }
11 : p1.X = 110;
12 : p1.Y = 220;
13 : p2.X = 330;
14 : p2.Y = 440;
15 : p1.Print();
16 : p2.Print();
17 : }
18 : }
1 : class Customer
2 : {
3 : private int id;
4 : private string lastName;
5 : private string firstName;
6 : private DateTime birthdate;
7 : private string creditCardNumber;
8 : public Customer(int id) { this.id = id; }
9 : public int ID
10 : {
11 : get { return id; }
12 : }
13 : public string LastName
14 : {
15 : get { return this.lastName; }
16 : set { this.lastName = value; }
17 : }
18 : public string FirstName
19 : {
20 : get { return this.firstName; }
21 : set { this.firstName = value; }
22 : }
23 : public DateTime Birthdate
24 : {
25 : get { return birthdate; }
26 : set { birthdate = value; }
27 : }
28 : public string CreditCardNumber
29 : {
30 : get
31 : {
32 : string last_numbers = creditCardNumber.Substring(creditCardNumber.Length - 4);
33 : return last_numbers;
34 : }
35 : set { creditCardNumber = value; }
36 : }
37 : public int Age
38 : {
39 : get
40 : {
41 : int year = DateTime.Now.Year;
42 : return year - birthdate.Year;
43 : }
44 : }
45 : public void Print()
46 : {
47 : Console.WriteLine("ID:{0},Last Name:{1},First Name:{2}", id, lastName, firstName);
48 : Console.WriteLine("Birthdate:{0}", birthdate.ToShortDateString());
49 : Console.WriteLine("Credit Card : XXXX-{0}", CreditCardNumber);
50 : }
51 : }
1 : class Program
2 : {
3 : static void Main(string[] args)
4 : {
5 : Customer customer = new Customer(123456);
6 : customer.LastName = "Israeli";
7 : customer.FirstName = "Moshe";
8 : customer.CreditCardNumber = "1234-5678-2345-6789";
9 : customer.Birthdate = new DateTime(1981, 3, 23);
10 : customer.Print();
11 : }
12 : }