Interfaces Cannot Declare Type Issue C#

前端 未结 3 1078
迷失自我
迷失自我 2020-12-20 23:57

This question is more aimed at good design practices rather than exceptions and stacks. My apologies for not being clear at first.

I want to play about with havin

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-21 00:24

    Perhaps I'm missing something in your design but, you don't need to do anything special to make sure a class "can" throw an exception. Any class can throw any exception it wants any time. The only requirement is that the exception class be visible.

    Make sure the exception is in the same assembly and same namespace as your interface and you'll be fine.

    public interface IStack
    {   
        bool IsEmpty();
        int Pop();
        void Push(int element);
        int Size { get; set; }
        int Top();
    }   
    
    
    public class Empty : Exception
    {
    }
    

提交回复
热议问题