Why does [Enum] .Parse have an ignoreCase parameter?

Since the enumeration in VB.Net cannot contain duplicate values, such as:

Enum Test A a End Enum 

Then why does the [Enum].Parse have a StringCase parameter?

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

http://msdn.microsoft.com/en-us/library/system.enum.parse.aspx

Parse (Type, String, Boolean)

It really makes sense to me.

What did the developers of class logic in the .NET Framework write this ignorecase flag in this method?

I think the logic of [Enum].Parse should be to automatically check the ignorecase value instead of passing the boolean parameter to the method, because the enumeration cannot contain duplicates ... or can it contain?

+6
source share
1 answer

An enumeration may contain values ​​that differ only in the case - you simply cannot declare them in VB. This is perfectly true in C #:

 public enum Foo { A, a; } 

In addition, even if the enumeration cannot contain values ​​that differ only in the case, this does not mean that you always want it to be case sensitive or always require it to be case insensitive. You assume that it should always be case insensitive, it will be annoying when you tried to ensure case-sensitive case-sensitivity. It is very rare to make case insensitive case the only option in the API, IMO.

+10
source

Source: https://habr.com/ru/post/956391/


All Articles