Pattern matching equal null vs is null

后端 未结 3 610
有刺的猬
有刺的猬 2021-01-02 09:49

From Microsoft new-features-in-c-7-0:

public void PrintStars(object o)
{
    if (o is null) return;     // constant pattern \"null\"
    if (!(o is int i)) r         


        
3条回答
  •  無奈伤痛
    2021-01-02 10:13

    The differences between "is" and == is "is" special that it act as == if you compare to value and act as typeof(type) when you compare type of object to type.

提交回复
热议问题