This article is a mirror article of machine translation, please click here to jump to the original article.

View: 27038|Reply: 2

[Source] enum enum checks if a value is included in an enum

[Copy link]
Posted on 4/11/2018 3:58:53 PM | | |
  • By default, the first value of the enumeration is 0, which can be explicitly assigned to the enum.
  • You can define the base type of the enum, such as enum E : short {}, sizeof(E) == 2; int by default.
  • Enumerated inheritance chain: ValueType->Enum->enum
  • The conversion between the enum type and the base type is explicit, except for 0, because there is an implicit conversion from 0 to any enum type.
  • The enum's ToString() outputs the identifier of its enum value,
  • From string to enumeration: AEnumType a = (AEnumType) Enum.Parse(typeof(AEnumType), "flag"); may fail, and the code should include exception handling mechanisms.
  • You can use Enum.IsDefined() to check if a value is included in an enum.


if (! Enum.IsDefined(typeof(SearchMode), options))
              throw new ArgumentException(Properties.Resources.InvalidEnumerationValue, "options");

SearchMode is an enum type, if the passing options value is not within the scope of this enum definition,For example, if an enum defines 1,2, and options are from 3 casts, then the IsDefined method returns false.






Previous:The IIS Express web server could not be started
Next:StackOverflow is so big, what is its architecture?
 Landlord| Posted on 3/29/2023 3:28:04 PM |
C# checks if int can be converted to an enum enum type

 Landlord| Posted on 8/14/2023 9:20:03 AM |
C# enums use the Flags feature, where multiple values are stored in one enumeration variable
https://www.itsvse.com/thread-4661-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com