ElektroStudios ElektroStudios - 1 year ago 158
Vb.net Question

Why [Enum].Parse has an ignoreCase parameter?

Since an Enumeration in VB.Net cannot contains duplicated values like this:

Enum Test
End Enum

Then why the
method has a StringCase parameter?

[Enum].Parse(GetType(Enum), Value, Ignorecase)


Parse(Type, String, Boolean)

It really has any sense for me.

Which with logic developers of .NET Framework Classes has written that ignorecase flag in that method?

I think that the
logic should be to check automatically for ignorecase value instead of passing a boolean parameter to the method because an enum cannot contains duplicates ...or it can contains?

Answer Source

An enum can contain values which differ only in case - you just can't declare them in VB. This is perfectly valid C#:

public enum Foo
    A, a;

Additionally, even if the enum couldn't contain values differing only in case, that wouldn't mean you'd either always want it to be case-sensitive or always want it to be case-insensitive. Your suggest that it should always be case-insensitive would be annoying for situations where you were trying to provide a case-sensitive match. It's very rarely a good idea to make case-insensitive matching the only option in an API, IMO.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download