Implement an Interface with Generic Methods

前端 未结 3 1514
天涯浪人
天涯浪人 2021-01-30 06:27

I\'m drawing a blank on this one and can\'t seem to find any previous example that I wrote. I\'m trying to implement a generic interface with a class. When I implement the inter

3条回答
  •  一个人的身影
    2021-01-30 06:56

    -- Edit

    The other answers are better, but note you can have VS implement the interface for you, if you are confused as to how it should look.

    Process described below.

    Well, Visual Studio tells me it should look like this:

    class X : IOurTemplate
    {
        #region IOurTemplate Members
    
        IEnumerable IOurTemplate.List()
        {
            throw new NotImplementedException();
        }
    
        T IOurTemplate.Get(U id)
        {
            throw new NotImplementedException();
        }
    
        #endregion
    }
    

    Note that all I did was write interface, then click on it, and wait for the little icon to popup to have VS generate the implementation for me :)

提交回复
热议问题