I have an enum (let’s say DemoEnum) and I want to parse a value to this enum. I am writing
DemoEnum value;
if(DemoEnum.TryParse("input", out value))
{
this.Value = value;
}
Now the resharper suggests me, to use the base class qualifier.
I just want to know what’s the benefit of using the base class qualifier?
Generally, it is a good idea to use the most generic solution possible.
Is the same call as (you’re just making the static call from an inherited class rather than the base class):
Using the base class qualifier (
Enum) instead of your specific enum (DemoEnum) would insulate you from possible side effects of changingDemoEnumin the future. The reality is that you’re really only going to run into issues if you change DemoEnum to a class without changing the name.This is generally a larger issue when using classes (and ReSharper will give the same guidance in those situations).