Code snippet for declaration and use of c\

From , 3 Years ago, written in C#, viewed 52 times.
URL https://pastebin.vip/view/51a472c0
  1. // person.cs
  2. using System;
  3. class Person
  4. {
  5.     private string myName ="N/A";
  6.     private int myAge = 0;
  7.  
  8.     // 声明 string 类型的 Name 属性:
  9.     public string Name
  10.     {
  11.         get
  12.         {
  13.            return myName;
  14.         }
  15.         set
  16.         {
  17.            myName = value;
  18.         }
  19.     }
  20.  
  21.     // 声明 int 类型的 Age 属性:
  22.     public int Age
  23.     {
  24.         get
  25.         {
  26.            return myAge;
  27.         }
  28.         set
  29.         {
  30.            myAge = value;
  31.         }
  32.     }
  33.  
  34.     public override string ToString()
  35.     {
  36.         return "Name = " + Name + ", Age = " + Age;
  37.     }
  38.  
  39.     public static void Main()
  40.     {
  41.         Console.WriteLine("Simple Properties");
  42.  
  43.         // 创建新的 Person 对象:
  44.         Person person = new Person();
  45.  
  46.         // 打印出与该对象关联的姓名和年龄:
  47.         Console.WriteLine("Person details - {0}", person);
  48.  
  49.         // 设置 Person 对象的某些值:
  50.         person.Name = "Joe";
  51.         person.Age = 99;
  52.         Console.WriteLine("Person details - {0}", person);
  53.  
  54.         // 递增 Age 属性:
  55.         person.Age += 1;
  56.         Console.WriteLine("Person details - {0}", person);
  57.     }
  58. }
  59.  
  60. //csharp/4921

Reply to "Code snippet for declaration and use of c\"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website