⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interfacestest.cs

📁 this is a good book for the visual c#
💻 CS
字号:
// Fig. 10.18: InterfacesTest.cs
// Demonstrating polymorphism with interfaces.
using System.Windows.Forms;

public class InterfacesTest
{
   public static void Main( string[] args )
   {
      Tree tree = new Tree( 1978 );
      Person person = new Person( "Bob", "Jones", 1971 );

      // create array of IAge references
      IAge[] iAgeArray = new IAge[ 2 ];
 
      // iAgeArray[ 0 ] refers to Tree object polymorphically
      iAgeArray[ 0 ] = tree;

      // iAgeArray[ 1 ] refers to Person object polymorphically
      iAgeArray[ 1 ] = person;

      // display tree information
      string output = tree + ": " + tree.Name + "\nAge is " + 
         tree.Age + "\n\n";

      // display person information
      output += person + ": " + person.Name + "\nAge is: " 
         + person.Age + "\n\n";

      // display name and age for each IAge object in iAgeArray
      foreach ( IAge ageReference in iAgeArray )
      {
         output += ageReference.Name + ": Age is " + 
            ageReference.Age + "\n";
      }

      MessageBox.Show( output, "Demonstrating Polymorphism" );

   } // end method Main

} // end class InterfacesTest

⌨️ 快捷键说明

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