Sealing an interface after implementing it

前端 未结 5 473
天命终不由人
天命终不由人 2021-01-02 16:00

I am working on a small project and I came across that problem.

The project output is a library containing an interface. I would like to implement that interface and

5条回答
  •  误落风尘
    2021-01-02 16:29

    Methods in C# are sealed by default.. Here is a sample

    class Program
    {
        static void Main(string[] args)
        {
    
            A obj = new A();
            obj.SomeMethod();
            b ss = new b();
            ss.SomeMethod();
            Console.ReadLine();
        }
    }
    
    public interface ITest { void SomeMethod(); }
    
    class A : ITest { public void SomeMethod() {
    
        Console.WriteLine("SomeMethod Called from Class A object");
    } }
    
    class b : A
    {
        //public override void SomeMethod()
        //{
        //    Console.WriteLine("Called from Class B Object");
        //}
    }
    

提交回复
热议问题