Why is a property hiding Inherited function with same name?

前端 未结 2 1780
日久生厌
日久生厌 2021-01-21 03:59

I have a class Foo with a function myName in it.
Class bar Inherits from Foo and have a Property that is also called

2条回答
  •  执念已碎
    2021-01-21 04:26

    We don't even need inheritance in the picture - you can't have "overloads" between a property and a method:

    class Program
    {
        static void Main(string[] args)
        {
    
            Console.ReadLine();
        }
    
        void DoStuff(int i,int j)
        {
    
        }
    
        int DoStuff { get { return 10; } }
    }
    

    Produces:

    error CS0102: The type 'ConsoleApplication4.Program' already contains a definition for 'DoStuff'

提交回复
热议问题