Quantcast
Channel: 2,000 Things You Should Know About C# » Visual Studio
Viewing all articles
Browse latest Browse all 21

#770 – Use Intellisense to Get List of Methods to Override

$
0
0

In a derived class, you can override a member of the base class if it’s declared as virtual.  In Visual Studio, the Intellisense feature can help you to discover the methods that can be overridden.

Suppose that we have the following definition for Dog:

    public class Dog
    {
        public virtual string Prop1 { get; set; }
        public string Prop2 { get; set; }

        public virtual void Method1()
        {
            Console.WriteLine("Dog.Method1");
        }

        public void Method2()
        {
            Console.WriteLine("Dog.Method2");
        }
    }

Now when we are adding code to a child class of Dog, we can just enter the keyword override, followed by a space, to see a list of candidate members that can be overridden.

770-001

To add the code for one of these members, just use the down arrow to select the method and then press TAB.  The body of the method will be generated for you.

770-002


Filed under: Visual Studio Tagged: C#, Intellisense, override, Visual Studio

Viewing all articles
Browse latest Browse all 21

Trending Articles