The type arguments for method cannot be inferred from the usage

前端 未结 6 1728
盖世英雄少女心
盖世英雄少女心 2020-12-05 04:16

Maybe I\'m overworked, but this isn\'t compiling (CS0411). Why?

interface ISignatur
{
    Type Type { get; }
}

interface IAccess where          


        
6条回答
  •  猫巷女王i
    2020-12-05 04:24

    I wanted to make a simple and understandable example

    if you call a method like this, your client will not know return type

    var interestPoints = Mediator.Handle(new InterestPointTypeRequest
                {
                    LanguageCode = request.LanguageCode,
                    AgentId = request.AgentId,
                    InterestPointId = request.InterestPointId,
                });
    

    Then you should say to compiler i know the return type is List

    var interestPoints  = Mediator.Handle>(new InterestPointTypeRequest
                {
                    LanguageCode = request.LanguageCode,
                    AgentId = request.AgentId,
                    InterestPointId = request.InterestPointId,
                    InterestPointTypeId = request.InterestPointTypeId
                });
    

    the compiler will no longer be mad at you for knowing the return type

提交回复
热议问题