C#C
C#3y ago
FusedQyou

❔ Check if Type is static

This question is probably vague as shit, but I always do this check to ensure a type is static:
private bool IsStatic(Type type)
{
  return type.IsAbstract && type.IsSealed;
}

So, this works because static classes are declared abstract and sealed at the IL level.
My question is if this is actually valid and won't fail, ever. C# doesn't exactly have a isStatic field or something.
Was this page helpful?