如何:实现抽象基类

更新:2007 年 11 月

使用此过程可以执行“实现抽象基类”IntelliSense 操作。有关更多信息,请参见实现抽象基类

使用 IntelliSense 实现抽象基类

  1. 创建一个控制台应用程序。有关更多信息,请参见控制台应用程序模板

  2. 将光标置于 class Program 语句之后。

  3. 键入 : StringComparer ,以使类声明成为 class Program : StringComparer。

  4. 单击 StringComparer 下的智能标记,再单击“实现抽象类‘System.StringComparer’”。

    IntelliSense 会向 Program 类中添加 StringComparer 类中的三个重写方法。

    using System;
    using System.Collections.Generic;
    using System.Text;
    namespace ConsoleApplication1
    {
        class Program : StringComparer
        {
            static void Main(string[] args)
            {
    
                }
    
                public override int Compare(string x, string y)
                {
                    throw new Exception ("The method or operation is not implemented.");
                }
    
                public override bool Equals(string x, string y)
                {
                    throw new Exception ("The method or operation is not implemented.");
                }
                public override int GetHashCode(string obj)
                {
                    throw new Exception ("The method or operation is not implemented.");
                }
    
        }
    }
    

示例

通过开发环境创建的新控制台应用程序以下面的声明开始。

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
     class Program
     {
          static void Main(string[] args)
          {
     
          }
      }
}

请参见

参考

实现抽象基类

StringComparer

其他资源

自动代码生成