Generic vs not-generic performance in C#

后端 未结 8 1568
旧巷少年郎
旧巷少年郎 2020-12-25 13:21

I\'ve written two equivalent methods:

static bool F(T a, T b) where T : class
{
    return a == b;
}

static bool F2(A a, A b)
{
    return a == b;
         


        
8条回答
  •  無奈伤痛
    2020-12-25 13:46

    Stop worrying about timing, worry about correctness.

    Those methods are not equivalent. One of them uses class A's operator== and the other uses object's operator==.

提交回复
热议问题