次の方法で共有


方法 : 抽象基本クラスを実装する

ここでは、IntelliSense の抽象基本クラス実装機能を使用する手順について説明します。 詳細については、「抽象基本クラスの実装」を参照してください。

IntelliSense を使用して抽象基本クラスを実装するには

  1. コンソール アプリケーションを作成します。

  2. class Program ステートメントの後にカーソルを置きます。

  3. 「: StringComparer 」と入力して、class Program : StringComparer となるようにクラス宣言を記述します。

  4. StringComparer の下のスマート タグをクリックし、[抽象クラス 'System.StringComparer' を実装します。] をクリックします。

    StringComparer クラスから Program クラスへオーバーライド メソッドが 3 つ追加されます。

    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

その他の技術情報

自動コード生成