System.Guid is a struct, which cannot be null as it is not a reference type. I believe that for known struct
types that implement custom equality operator (e.g. int, Guid etc) the compiler will substitute the null comparison with false. (Hence the whole comparison and throw statement will disappear)
For the struct
types that do not implement custom equality operator, the code simply won't compile.
Nonetheless, it is unnecessary.
See: https://sharplab.io/#v2:EYLgtghgzgLgpgJwDQxASwDYB8ACAGAAhwEYBuAWACgcBmIgJgIGECBvKgzounAFgICyACgDiAVzQATAgHMJkgJRsOXVWgBmBIXKkEAvHoIA7MRgxKYACwQB7AO7G4DgIII5YOEZgA5UxgCiAB4AxnAADjBoNkZCChSUqgC+VIlAA===
public void M(Guid guid)
{
if (guid == null) throw new ArgumentNullException();
}
will be compiled to:
// Methods
.method public hidebysig
instance void M (
valuetype [mscorlib]System.Guid guid
) cil managed
{
// Method begins at RVA 0x2050
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method C::M
As you can see, the first instruction in the method is return.