We recommend using Visual Studio 2017

IntelliSense for Override

IntelliSense is designed to help you override inherited members. When you type override and then press SPACE, IntelliSense shows you all of the valid base class members that you can override in a pop-up list box.

Note   To disambiguate virtual methods with the same name and different parameter lists, IntelliSense displays their signature in the pop-up list box.

When you proceed on a member from the pop-up list box, IntelliSense generates the code that completes the member that you selected and highlights the first logical statement to edit.

Example

Through this example, learn how to use IntelliSense to override the Refresh method of a Windows Form.

To override a method

  1. Create a C# Windows application, and then use the View Code command to open Form1.cs in the Code Editor.
  2. In the class Form1, type override on its own line before the closing brace, and then press SPACE. A list box appears with all the valid base class members that you can override.
    Note   You can skip this option by pressing ESC or by continuing to type.
  3. Select the Refresh method, and then press ENTER. The following code is generated for you:
    public override void Refresh()
    {
       base.Refresh();
    }
    

    The statement base.Refresh(); is highlighted so that you can immediately begin editing this code.

Example

This example shows how to use IntelliSense to override a user defined virtual method and how IntelliSense displays overloaded virtual methods in the pop-up list box.

To override a user defined virtual method

  1. Create a C# console application, and then use the View Code command to open Class1.cs in the Code Editor.
  2. In the Code Editor, add the following class named Employee:
    class Employee
    {
       virtual public void CaculatePay(int EmployeeID)
       {
       }
       virtual public void CaculatePay(string EmployeeName)
       {
       }
    }
    
  3. Create another class named SalariedEmployee that inherits from Employee, for example:
    class SalariedEmployee : Employee
    {
    }
    
  4. Type the override modifier in the body of SalariedEmployee, and then press SPACE. A list box appears with all the valid base class members that you can override, including the overloaded method CalculatePay.
    Note   To disambiguate virtual methods with the same name and different parameter lists, IntelliSense displays their signature in the pop-up list box.
  5. Select CalculatePay (int EmployeeID). IntelliSense generates the following override construct for you:
    public override void CaculatePay(int EmployeeID)
    {
       base.CaculatePay (EmployeeID);
    }
    

See Also

Visual C# IntelliSense

Show: