myVariable(int)== 0与myVariable(Guid)== Guid.Empty相同

时间:2021-03-04 23:00:56

I recently converted a bunch of tables PK's from int to uniqueidentifier. Now in my code I am replacing certain checks like so:

我最近将一堆表PK从int转换为uniqueidentifier。现在在我的代码中,我正在替换某些检查,如下所示:

if (planDiagnosisID != 0)

with

if (planDiagnosisID != Guid.Empty)

Where planDiagnosisID is an int in the first one and a Guid in the second.

其中planDiagnosisID在第一个中是int而在第二个中是Guid。

Is this accurate?

这准确吗?

1 个解决方案

#1


5  

Yes that is correct. Guid.Empty is the default value for Guid. It is a value type, so it can't be null.

对,那是正确的。 Guid.Empty是Guid的默认值。它是一个值类型,因此不能为null。

Or in code

或者在代码中

default(Guid) == Guid.Empty

Just as

就像

default(int) == 0

#1


5  

Yes that is correct. Guid.Empty is the default value for Guid. It is a value type, so it can't be null.

对,那是正确的。 Guid.Empty是Guid的默认值。它是一个值类型,因此不能为null。

Or in code

或者在代码中

default(Guid) == Guid.Empty

Just as

就像

default(int) == 0