tree.cs

来自「this is a good book for the visual c#」· CS 代码 · 共 40 行

CS
40
字号
// Fig. 10.17: Tree.cs
// Class Tree contains number of rings corresponding to its age.
using System;

public class Tree : IAge
{
   private int rings; // number of rings in tree trunk

   // constructor
   public Tree( int yearPlanted )
   {
      // count number of rings in Tree
      rings = DateTime.Now.Year - yearPlanted;
   }

   // increment ring
   public void AddRing()
   {
      rings++;
   }

   // property Age implementation of interface IAge
   public int Age
   {
      get
      {
         return rings;
      }
   }

   // property Name implementation of interface IAge
   public string Name
   {
      get
      {
         return "Tree";
      }
   }

} // end class Tree

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?