Can't operator == be applied to generic types in C#?

前端 未结 12 649
囚心锁ツ
囚心锁ツ 2020-11-22 02:21

According to the documentation of the == operator in MSDN,

For predefined value types, the equality operator (==) returns true if th

12条回答
  •  名媛妹妹
    2020-11-22 02:46

    The .Equals() works for me while TKey is a generic type.

    public virtual TOutputDto GetOne(TKey id)
    {
        var entity =
            _unitOfWork.BaseRepository
                .FindByCondition(x => 
                    !x.IsDelete && 
                    x.Id.Equals(id))
                .SingleOrDefault();
    
    
        // ...
    }
    

提交回复
热议问题