-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathEnum.xml
4796 lines (4526 loc) · 352 KB
/
Enum.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<Type Name="Enum" FullName="System.Enum">
<TypeSignature Language="C#" Value="public abstract class Enum : ValueType, IComparable, IConvertible, IFormattable" FrameworkAlternate="dotnet-uwp-10.0;net-5.0;net-6.0;net-7.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract beforefieldinit Enum extends System.ValueType implements class System.IComparable, class System.IConvertible, class System.IFormattable" FrameworkAlternate="dotnet-uwp-10.0;net-5.0;net-6.0;net-7.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="DocId" Value="T:System.Enum" />
<TypeSignature Language="VB.NET" Value="Public MustInherit Class Enum
Inherits ValueType
Implements IComparable, IConvertible, IFormattable" FrameworkAlternate="dotnet-uwp-10.0;net-5.0;net-6.0;net-7.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<TypeSignature Language="F#" Value="type Enum = class
 inherit ValueType
 interface IComparable
 interface IConvertible
 interface IFormattable" FrameworkAlternate="dotnet-uwp-10.0;net-5.0;net-6.0;net-7.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="C++ CLI" Value="public ref class Enum abstract : ValueType, IComparable, IConvertible, IFormattable" FrameworkAlternate="dotnet-uwp-10.0;net-5.0;net-6.0;net-7.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<TypeSignature Language="C#" Value="public abstract class Enum : ValueType, IComparable, IConvertible, ISpanFormattable" FrameworkAlternate="net-8.0" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract beforefieldinit Enum extends System.ValueType implements class System.IComparable, class System.IConvertible, class System.IFormattable, class System.ISpanFormattable" FrameworkAlternate="net-8.0" />
<TypeSignature Language="VB.NET" Value="Public MustInherit Class Enum
Inherits ValueType
Implements IComparable, IConvertible, ISpanFormattable" FrameworkAlternate="net-8.0" />
<TypeSignature Language="F#" Value="type Enum = class
 inherit ValueType
 interface IComparable
 interface IConvertible
 interface ISpanFormattable
 interface IFormattable" FrameworkAlternate="net-8.0" />
<TypeSignature Language="C++ CLI" Value="public ref class Enum abstract : ValueType, IComparable, IConvertible, ISpanFormattable" FrameworkAlternate="net-8.0" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract serializable beforefieldinit Enum extends System.ValueType implements class System.IComparable, class System.IConvertible, class System.IFormattable" FrameworkAlternate="netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<TypeSignature Language="F#" Value="type Enum = class
 inherit ValueType
 interface IComparable
 interface IFormattable
 interface IConvertible" FrameworkAlternate="netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<TypeSignature Language="C#" Value="public abstract class Enum : ValueType, IComparable, IFormattable" FrameworkAlternate="netstandard-1.0;netstandard-1.1;netstandard-1.2" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract beforefieldinit Enum extends System.ValueType implements class System.IComparable, class System.IFormattable" FrameworkAlternate="netstandard-1.0;netstandard-1.1;netstandard-1.2" />
<TypeSignature Language="VB.NET" Value="Public MustInherit Class Enum
Inherits ValueType
Implements IComparable, IFormattable" FrameworkAlternate="netstandard-1.0;netstandard-1.1;netstandard-1.2" />
<TypeSignature Language="F#" Value="type Enum = class
 inherit ValueType
 interface IComparable
 interface IFormattable" FrameworkAlternate="netstandard-1.0;netstandard-1.1;netstandard-1.2" />
<TypeSignature Language="C++ CLI" Value="public ref class Enum abstract : ValueType, IComparable, IFormattable" FrameworkAlternate="netstandard-1.0;netstandard-1.1;netstandard-1.2" />
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeForwardingChain>
<TypeForwarding From="mscorlib" FromVersion="4.0.0.0" To="System.Runtime" ToVersion="0.0.0.0" FrameworkAlternate="dotnet-uwp-10.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="5.0.0.0" FrameworkAlternate="net-5.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="6.0.0.0" FrameworkAlternate="net-6.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
</TypeForwardingChain>
<Base>
<BaseTypeName>System.ValueType</BaseTypeName>
</Base>
<Interfaces>
<Interface>
<InterfaceName>System.IComparable</InterfaceName>
</Interface>
<Interface FrameworkAlternate="dotnet-uwp-10.0;net-5.0;net-6.0;net-7.0;net-8.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<InterfaceName>System.IConvertible</InterfaceName>
</Interface>
<Interface>
<InterfaceName>System.IFormattable</InterfaceName>
</Interface>
<Interface FrameworkAlternate="net-8.0">
<InterfaceName>System.ISpanFormattable</InterfaceName>
</Interface>
</Interfaces>
<Attributes>
<Attribute FrameworkAlternate="net-8.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(1)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(1)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName Language="C#">[System.Serializable]</AttributeName>
<AttributeName Language="F#">[<System.Serializable>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName Language="C#">[System.Runtime.InteropServices.ComVisible(true)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.InteropServices.ComVisible(true)>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Provides the base class for enumerations.</summary>
<remarks>
<format type="text/markdown">< section and the <xref:System.FlagsAttribute> topic.
In this topic:
[Creating an enumeration type](#Creating)
[Instantiating an enumeration type](#Instantiating)
[Enumeration best practices](#BestPractices)
[Performing operations with enumerations](#Operations)
[Performing conversions](#conversions)
[Parsing enumeration values](#parsing)
[Formatting enumeration values](#formatting)
[Iterating enumeration members](#iterating)
[Non-exclusive members and the Flags attribute](#Flags)
[Adding enumeration methods](#Methods)
<a name="Creating"></a>
## Creating an enumeration type
Programming languages typically provide syntax to declare an enumeration that consists of a set of named constants and their values. The following example illustrates the syntax used by C#, F#, and Visual Basic to define an enumeration. It creates an enumeration named `ArrivalStatus` that has three members: `ArrivalStatus.Early`, `ArrivalStatus.OnTime`, and `ArrivalStatus.Late`. Note that in all cases, the enumeration does not explicitly inherit from <xref:System.Enum>; the inheritance relationship is handled implicitly by the compiler.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/class1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/class1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/class1.vb" id="Snippet1":::
> [!WARNING]
> You should never create an enumeration type whose underlying type is non-integral or <xref:System.Char>. Although you can create such an enumeration type by using reflection, method calls that use the resulting type are unreliable and may also throw additional exceptions.
<a name="Instantiating"></a>
## Instantiating an enumeration type
You can instantiate an enumeration type just as you instantiate any other value type: by declaring a variable and assigning one of the enumeration's constants to it. The following example instantiates an `ArrivalStatus` whose value is `ArrivalStatus.OnTime`.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/class1.cs" id="Snippet2":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/class1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/class1.vb" id="Snippet2":::
You can also instantiate an enumeration value in the following ways:
- By using a particular programming language's features to cast (as in C#) or convert (as in Visual Basic) an integer value to an enumeration value. The following example creates an `ArrivalStatus` object whose value is `ArrivalStatus.Early` in this way.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/class2.cs" id="Snippet4":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/class2.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/class2.vb" id="Snippet4":::
- By calling its implicit parameterless constructor. As the following example shows, in this case the underlying value of the enumeration instance is 0. However, this is not necessarily the value of a valid constant in the enumeration.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/class2.cs" id="Snippet3":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/class2.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/class2.vb" id="Snippet3":::
- By calling the <xref:System.Enum.Parse%2A> or <xref:System.Enum.TryParse%2A> method to parse a string that contains the name of a constant in the enumeration. For more information, see the [Parsing Enumeration Values](#parsing) section.
- By calling the <xref:System.Enum.ToObject%2A> method to convert an integral value to an enumeration type. For more information, see the [Performing Conversions](#conversions) section.
<a name="BestPractices"></a>
## Enumeration best practices
We recommend that you use the following best practices when you define enumeration types:
- If you have not defined an enumeration member whose value is 0, consider creating a `None` enumerated constant. By default, the memory used for the enumeration is initialized to zero by the common language runtime. Consequently, if you do not define a constant whose value is zero, the enumeration will contain an illegal value when it is created.
- If there is an obvious default case that your application has to represent, consider using an enumerated constant whose value is zero to represent it. If there is no default case, consider using an enumerated constant whose value is zero to specify the case that is not represented by any of the other enumerated constants.
- Do not specify enumerated constants that are reserved for future use.
- When you define a method or property that takes an enumerated constant as a value, consider validating the value. The reason is that you can cast a numeric value to the enumeration type even if that numeric value is not defined in the enumeration.
Additional best practices for enumeration types whose constants are bit fields are listed in the [Non-Exclusive Members and the Flags Attribute](#Flags) section.
<a name="Operations"></a>
## Performing operations with enumerations
You cannot define new methods when you are creating an enumeration. However, an enumeration type inherits a complete set of static and instance methods from the <xref:System.Enum> class. The following sections survey most of these methods, in addition to several other methods that are commonly used when working with enumeration values.
<a name="conversions"></a>
### Performing conversions
You can convert between an enumeration member and its underlying type by using a casting (in C# and F#), or conversion (in Visual Basic) operator. In F#, the `enum` function is also used. The following example uses casting or conversion operators to perform conversions both from an integer to an enumeration value and from an enumeration value to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/class2.cs" id="Snippet5":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/class2.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/class2.vb" id="Snippet5":::
The <xref:System.Enum> class also includes a <xref:System.Enum.ToObject%2A> method that converts a value of any integral type to an enumeration value. The following example uses the <xref:System.Enum.ToObject%28System.Type%2CSystem.Int32%29> method to convert an <xref:System.Int32> to an `ArrivalStatus` value. Note that, because the <xref:System.Enum.ToObject%2A> returns a value of type <xref:System.Object>, the use of a casting or conversion operator may still be necessary to cast the object to the enumeration type.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/class2.cs" id="Snippet6":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/class2.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/class2.vb" id="Snippet6":::
When converting an integer to an enumeration value, it is possible to assign a value that is not actually a member of the enumeration. To prevent this, you can pass the integer to the <xref:System.Enum.IsDefined%2A> method before performing the conversion. The following example uses this method to determine whether the elements in an array of integer values can be converted to `ArrivalStatus` values.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classconversion1.cs" interactive="try-dotnet" id="Snippet7":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classconversion1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classconversion1.vb" id="Snippet7":::
Although the <xref:System.Enum> class provides explicit interface implementations of the <xref:System.IConvertible> interface for converting from an enumeration value to an integral type, you should use the methods of the <xref:System.Convert> class, such as <xref:System.Convert.ToInt32%2A>, to perform these conversions. The following example illustrates how you can use the <xref:System.Enum.GetUnderlyingType%2A> method along with the <xref:System.Convert.ChangeType%2A?displayProperty=nameWithType> method to convert an enumeration value to its underlying type. Note that this example does not require the underlying type of the enumeration to be known at compile time.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classconversion2.cs" id="Snippet8":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classconversion2.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classconversion2.vb" id="Snippet8":::
<a name="parsing"></a>
### Parsing enumeration values
The <xref:System.Enum.Parse%2A> and <xref:System.Enum.TryParse%2A> methods allow you to convert the string representation of an enumeration value to that value. The string representation can be either the name or the underlying value of an enumeration constant. Note that the parsing methods will successfully convert string representations of numbers that are not members of a particular enumeration if the strings can be converted to a value of the enumeration's underlying type. To prevent this, the <xref:System.Enum.IsDefined%2A> method can be called to ensure that the result of the parsing method is a valid enumeration value. The example illustrates this approach and demonstrates calls to both the <xref:System.Enum.Parse%28System.Type%2CSystem.String%29> and <xref:System.Enum.TryParse%60%601%28System.String%2C%60%600%40%29?displayProperty=nameWithType> methods. Note that the non-generic parsing method returns an object that you may have to cast (in C# and F#) or convert (in Visual Basic) to the appropriate enumeration type.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classparse1.cs" id="Snippet9":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classparse1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classparse1.vb" id="Snippet9":::
<a name="formatting"></a>
### Formatting enumeration values
You can convert enumeration values to their string representations by calling the static <xref:System.Enum.Format%2A> method, as well as the overloads of the instance <xref:System.Enum.ToString%2A> method. You can use a format string to control the precise way in which an enumeration value is represented as a string. For more information, see [Enumeration Format Strings](/dotnet/standard/base-types/enumeration-format-strings). The following example uses each of the supported enumeration format strings ("G" or "g", "D" or "d", "X" or "x", and "F" or "f" ) to convert a member of the `ArrivalStatus` enumeration to its string representations.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classformat1.cs" id="Snippet10":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classformat1.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classformat1.vb" id="Snippet10":::
<a name="iterating"></a>
### Iterating enumeration members
The <xref:System.Enum> type does not implement the <xref:System.Collections.IEnumerable> or <xref:System.Collections.Generic.IEnumerable%601> interface, which would enable you to iterate members of a collection by using a `foreach` (in C#), `for..in` (in F#), or `For Each` (in Visual Basic) construct. However, you can enumerate members in either of two ways.
- You can call the <xref:System.Enum.GetNames%2A> method to retrieve a string array containing the names of the enumeration members. Next, for each element of the string array, you can call the <xref:System.Enum.Parse%2A> method to convert the string to its equivalent enumeration value. The following example illustrates this approach.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classiterate.cs" id="Snippet11":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classiterate.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classiterate.vb" id="Snippet11":::
- You can call the <xref:System.Enum.GetValues%2A> method to retrieve an array that contains the underlying values in the enumeration. Next, for each element of the array, you can call the <xref:System.Enum.ToObject%2A> method to convert the integer to its equivalent enumeration value. The following example illustrates this approach.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classiterate.cs" id="Snippet12":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classiterate.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classiterate.vb" id="Snippet12":::
<a name="Flags"></a>
## Non-exclusive members and the Flags attribute
One common use of an enumeration is to represent a set of mutually exclusive values. For example, an `ArrivalStatus` instance can have a value of `Early`, `OnTime`, or `Late`. It makes no sense for the value of an `ArrivalStatus` instance to reflect more than one enumeration constant.
In other cases, however, the value of an enumeration object can include multiple enumeration members, and each member represents a bit field in the enumeration value. The <xref:System.FlagsAttribute> attribute can be used to indicate that the enumeration consists of bit fields. For example, an enumeration named `Pets` might be used to indicate the kinds of pets in a household. It can be defined as follows.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classbitwise1.cs" id="Snippet13":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classbitwise1.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classbitwise1.vb" id="Snippet13":::
The `Pets` enumeration can then be used as shown in the following example.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classbitwise1.cs" id="Snippet14":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classbitwise1.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classbitwise1.vb" id="Snippet14":::
The following best practices should be used when defining a bitwise enumeration and applying the <xref:System.FlagsAttribute> attribute.
- Use the <xref:System.FlagsAttribute> custom attribute for an enumeration only if a bitwise operation (AND, OR, EXCLUSIVE OR) is to be performed on a numeric value.
- Define enumeration constants in powers of two, that is, 1, 2, 4, 8, and so on. This means the individual flags in combined enumeration constants do not overlap.
- Consider creating an enumerated constant for commonly used flag combinations. For example, if you have an enumeration used for file I/O operations that contains the enumerated constants `Read = 1` and `Write = 2`, consider creating the enumerated constant `ReadWrite = Read OR Write`, which combines the `Read` and `Write` flags. In addition, the bitwise OR operation used to combine the flags might be considered an advanced concept in some circumstances that should not be required for simple tasks.
- Use caution if you define a negative number as a flag enumerated constant because many flag positions might be set to 1, which might make your code confusing and encourage coding errors.
- A convenient way to test whether a flag is set in a numeric value is to call the instance <xref:System.Enum.HasFlag%2A> method, as shown in the following example.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classbitwise1.cs" id="Snippet15":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classbitwise1.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classbitwise1.vb" id="Snippet15":::
It is equivalent to performing a bitwise AND operation between the numeric value and the flag enumerated constant, which sets all bits in the numeric value to zero that do not correspond to the flag, and then testing whether the result of that operation is equal to the flag enumerated constant. This is illustrated in the following example.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classbitwise1.cs" id="Snippet16":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classbitwise1.fs" id="Snippet16":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classbitwise1.vb" id="Snippet16":::
- Use `None` as the name of the flag enumerated constant whose value is zero. You cannot use the `None` enumerated constant in a bitwise AND operation to test for a flag because the result is always zero. However, you can perform a logical, not a bitwise, comparison between the numeric value and the `None` enumerated constant to determine whether any bits in the numeric value are set. This is illustrated in the following example.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/classbitwise1.cs" id="Snippet17":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/classbitwise1.fs" id="Snippet17":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/classbitwise1.vb" id="Snippet17":::
- Do not define an enumeration value solely to mirror the state of the enumeration itself. For example, do not define an enumerated constant that merely marks the end of the enumeration. If you need to determine the last value of the enumeration, check for that value explicitly. In addition, you can perform a range check for the first and last enumerated constant if all values within the range are valid.
<a name="Methods"></a>
## Adding enumeration methods
Because enumeration types are defined by language structures, such as `enum` (C#), and `Enum` (Visual Basic), you cannot define custom methods for an enumeration type other than those methods inherited from the <xref:System.Enum> class. However, you can use extension methods to add functionality to a particular enumeration type.
In the following example, the `Grades` enumeration represents the possible letter grades that a student may receive in a class. An extension method named `Passing` is added to the `Grades` type so that each instance of that type now "knows" whether it represents a passing grade or not. The `Extensions` class also contains a static read-write variable that defines the minimum passing grade. The return value of the `Passing` extension method reflects the current value of that variable.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/Extensions.cs" interactive="try-dotnet" id="Snippet18":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/Extensions.fs" id="Snippet18":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.class/vb/Extensions.vb" id="Snippet18":::
## Examples
The following example demonstrates using an enumeration to represent named values and another enumeration to represent named bit fields.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/enummain/CPP/EnumMain.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Enum/Overview/EnumMain.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Overview/EnumMain.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/enummain/VB/EnumMain.vb" id="Snippet1":::
]]></format>
</remarks>
<threadsafe>This type is thread safe.</threadsafe>
<altmember cref="T:System.ValueType" />
<altmember cref="T:System.FlagsAttribute" />
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="protected Enum ();" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Enum.#ctor" />
<MemberSignature Language="VB.NET" Value="Protected Sub New ()" />
<MemberSignature Language="C++ CLI" Value="protected:
 Enum();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Enum" /> class.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="CompareTo">
<MemberSignature Language="C#" Value="public int CompareTo (object target);" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.0;netstandard-1.1;netstandard-1.2;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance int32 CompareTo(object target) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Enum.CompareTo(System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Function CompareTo (target As Object) As Integer" />
<MemberSignature Language="F#" Value="abstract member CompareTo : obj -> int
override this.CompareTo : obj -> int" Usage="enum.CompareTo target" />
<MemberSignature Language="C++ CLI" Value="public:
 virtual int CompareTo(System::Object ^ target);" />
<MemberSignature Language="C#" Value="public int CompareTo (object? target);" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;netcore-3.0;netcore-3.1" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember>M:System.IComparable.CompareTo(System.Object)</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-8.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(2)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.0;netstandard-1.1;netstandard-1.2;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName Language="C#">[System.Security.SecuritySafeCritical]</AttributeName>
<AttributeName Language="F#">[<System.Security.SecuritySafeCritical>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="target" Type="System.Object" />
</Parameters>
<Docs>
<param name="target">An object to compare, or <see langword="null" />.</param>
<summary>Compares this instance to a specified object and returns an indication of their relative values.</summary>
<returns>A signed number that indicates the relative values of this instance and <paramref name="target" />.
<list type="table"><listheader><term> Value
</term><description> Meaning
</description></listheader><item><term> Less than zero
</term><description> The value of this instance is less than the value of <paramref name="target" />.
</description></item><item><term> Zero
</term><description> The value of this instance is equal to the value of <paramref name="target" />.
</description></item><item><term> Greater than zero
</term><description> The value of this instance is greater than the value of <paramref name="target" />, or <paramref name="target" /> is <see langword="null" />.</description></item></list></returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Examples
The following example illustrates the use of `CompareTo` in the context of `Enum`.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/enumcompareto/CPP/EnumCompareTo.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Enum/CompareTo/EnumCompareTo.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/CompareTo/EnumCompareTo.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/enumcompareto/VB/EnumCompareTo.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">
<paramref name="target" /> and this instance are not the same type.</exception>
<exception cref="T:System.InvalidOperationException">This instance is not type <see cref="T:System.SByte" />, <see cref="T:System.Int16" />, <see cref="T:System.Int32" />, <see cref="T:System.Int64" />, <see cref="T:System.Byte" />, <see cref="T:System.UInt16" />, <see cref="T:System.UInt32" />, or <see cref="T:System.UInt64" />.</exception>
<altmember cref="M:System.Enum.Equals(System.Object)" />
<exception cref="T:System.NullReferenceException">This instance is null.</exception>
<inheritdoc />
</Docs>
</Member>
<Member MemberName="Equals">
<MemberSignature Language="C#" Value="public override bool Equals (object obj);" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.0;netstandard-1.1;netstandard-1.2;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance bool Equals(object obj) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Enum.Equals(System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function Equals (obj As Object) As Boolean" />
<MemberSignature Language="F#" Value="override this.Equals : obj -> bool" Usage="enum.Equals obj" />
<MemberSignature Language="C++ CLI" Value="public:
 override bool Equals(System::Object ^ obj);" />
<MemberSignature Language="C#" Value="public override bool Equals (object? obj);" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;netcore-3.0;netcore-3.1" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-8.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(2)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.0;netstandard-1.1;netstandard-1.2">
<AttributeName Language="C#">[System.Security.SecuritySafeCritical]</AttributeName>
<AttributeName Language="F#">[<System.Security.SecuritySafeCritical>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="obj" Type="System.Object">
<Attributes>
<Attribute FrameworkAlternate="net-6.0;net-7.0;net-8.0">
<AttributeName Language="C#">[System.Diagnostics.CodeAnalysis.NotNullWhen(true)]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.CodeAnalysis.NotNullWhen(true)>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="obj">An object to compare with this instance, or <see langword="null" />.</param>
<summary>Returns a value indicating whether this instance is equal to a specified object.</summary>
<returns>
<see langword="true" /> if <paramref name="obj" /> is an enumeration value of the same type and with the same underlying value as this instance; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Enum.Equals%28System.Object%29?displayProperty=nameWithType> method overrides <xref:System.ValueType.Equals%28System.Object%29?displayProperty=nameWithType> to define how enumeration members are evaluated for equality.
## Examples
The following example illustrates the use of the <xref:System.Enum.Equals%2A> method.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/enumequals/CPP/EnumEquals.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Enum/Equals/EnumEquals.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Equals/EnumEquals.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/enumequals/VB/EnumEquals.vb" id="Snippet1":::
The following example defines two enumeration types, `SledDog` and `WorkDog`. The `SledDog` enumeration has two members, `SledDog.AlaskanMalamute` and `SledDog.Malamute`, that have the same underlying value. The call to the <xref:System.Enum.Equals%2A> method indicates that these values are equal because their underlying values are the same. The `SledDog.Malamute` and `WorkDog.Newfoundland` members have the same underlying value, although they represent different enumeration types. A call to the <xref:System.Enum.Equals%2A> method indicates that these values are not equal.
:::code language="csharp" source="~/snippets/csharp/System/Enum/Equals/enumequals1.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Equals/enumequals1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.equals/vb/enumequals.vb" id="Snippet1":::
]]></format>
</remarks>
<altmember cref="M:System.Enum.CompareTo(System.Object)" />
<inheritdoc />
</Docs>
</Member>
<Member MemberName="Format">
<MemberSignature Language="C#" Value="public static string Format (Type enumType, object value, string format);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig string Format(class System.Type enumType, object value, string format) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Enum.Format(System.Type,System.Object,System.String)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function Format (enumType As Type, value As Object, format As String) As String" />
<MemberSignature Language="F#" Value="static member Format : Type * obj * string -> string" Usage="System.Enum.Format (enumType, value, format)" />
<MemberSignature Language="C++ CLI" Value="public:
 static System::String ^ Format(Type ^ enumType, System::Object ^ value, System::String ^ format);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName Language="C#">[System.Runtime.InteropServices.ComVisible(true)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.InteropServices.ComVisible(true)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="enumType" Type="System.Type" />
<Parameter Name="value" Type="System.Object" />
<Parameter Name="format" Type="System.String">
<Attributes>
<Attribute FrameworkAlternate="net-7.0;net-8.0">
<AttributeName Language="C#">[System.Diagnostics.CodeAnalysis.StringSyntax("EnumFormat")]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.CodeAnalysis.StringSyntax("EnumFormat")>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="enumType">The enumeration type of the value to convert.</param>
<param name="value">The value to convert.</param>
<param name="format">The output format to use.</param>
<summary>Converts the specified value of a specified enumerated type to its equivalent string representation according to the specified format.</summary>
<returns>A string representation of <paramref name="value" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The following table shows the valid values for the `format` parameter.
|Format|Description|
|------------|-----------------|
|"G" or "g"|If `value` is equal to a named enumerated constant, the name of that constant is returned; otherwise, the decimal equivalent of `value` is returned.<br /><br /> For example, suppose the only enumerated constant is named Red, and its value is 1. If `value` is specified as 1, this format returns "Red". However, if `value` is specified as 2, this format returns "2".<br /><br /> -or-<br /><br /> If the <xref:System.FlagsAttribute> custom attribute is applied to the enumeration, `value` is treated as a bit field that contains one or more flags that consist of one or more bits.<br /><br /> If `value` is equal to a combination of named enumerated constants, a delimiter-separated list of the names of those constants is returned. `value` is searched for flags, going from the flag with the largest value to the smallest value. For each flag that corresponds to a bit field in `value`, the name of the constant is concatenated to the delimiter-separated list. The value of that flag is then excluded from further consideration, and the search continues for the next flag.<br /><br /> If `value` is not equal to a combination of named enumerated constants, the decimal equivalent of `value` is returned.|
|"X" or "x"|Represents `value` in hexadecimal format without a leading "0x".|
|"D" or "d"|Represents `value` in decimal form.|
|"F" or "f"|Behaves identically to "G" or "g", except that the <xref:System.FlagsAttribute> is not required to be present on the <xref:System.Enum> declaration.|
## Examples
The following example illustrates the use of `Format` in the context of `Enum`.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/enumformat/CPP/EnumFormat.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Enum/Format/EnumFormat.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/Format/EnumFormat.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/enumformat/VB/EnumFormat.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">The <paramref name="enumType" />, <paramref name="value" />, or <paramref name="format" /> parameter is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">The <paramref name="enumType" /> parameter is not an <see cref="T:System.Enum" /> type.
-or-
The <paramref name="value" /> is from an enumeration that differs in type from <paramref name="enumType" />.
-or-
The type of <paramref name="value" /> is not an underlying type of <paramref name="enumType" />.</exception>
<exception cref="T:System.FormatException">The <paramref name="format" /> parameter contains an invalid value.</exception>
<exception cref="T:System.InvalidOperationException">
<paramref name="format" /> equals "X", but the enumeration type is unknown.
-or-
.NET 8 and later versions: <paramref name="enumType" /> is a Boolean-backed enumeration type.</exception>
<altmember cref="M:System.Enum.ToString(System.String)" />
<related type="Article" href="/dotnet/standard/base-types/formatting-types">Formatting Types in .NET</related>
<related type="Article" href="/dotnet/standard/base-types/enumeration-format-strings">Enumeration Format Strings</related>
</Docs>
</Member>
<Member MemberName="GetHashCode">
<MemberSignature Language="C#" Value="public override int GetHashCode ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance int32 GetHashCode() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Enum.GetHashCode" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function GetHashCode () As Integer" />
<MemberSignature Language="F#" Value="override this.GetHashCode : unit -> int" Usage="enum.GetHashCode " />
<MemberSignature Language="C++ CLI" Value="public:
 override int GetHashCode();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName Language="C#">[System.Security.SecuritySafeCritical]</AttributeName>
<AttributeName Language="F#">[<System.Security.SecuritySafeCritical>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns the hash code for the value of this instance.</summary>
<returns>A 32-bit signed integer hash code.</returns>
<remarks>To be added.</remarks>
<inheritdoc />
</Docs>
</Member>
<Member MemberName="GetName">
<MemberSignature Language="C#" Value="public static string GetName (Type enumType, object value);" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.0;netstandard-1.1;netstandard-1.2;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig string GetName(class System.Type enumType, object value) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Enum.GetName(System.Type,System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function GetName (enumType As Type, value As Object) As String" />
<MemberSignature Language="F#" Value="static member GetName : Type * obj -> string" Usage="System.Enum.GetName (enumType, value)" />
<MemberSignature Language="C++ CLI" Value="public:
 static System::String ^ GetName(Type ^ enumType, System::Object ^ value);" />
<MemberSignature Language="C#" Value="public static string? GetName (Type enumType, object value);" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;netcore-3.0;netcore-3.1" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName Language="C#">[System.Runtime.InteropServices.ComVisible(true)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.InteropServices.ComVisible(true)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="enumType" Type="System.Type" />
<Parameter Name="value" Type="System.Object" />
</Parameters>
<Docs>
<param name="enumType">An enumeration type.</param>
<param name="value">The value of a particular enumerated constant in terms of its underlying type.</param>
<summary>Retrieves the name of the constant in the specified enumeration that has the specified value.</summary>
<returns>A string containing the name of the enumerated constant in <paramref name="enumType" /> whose value is <paramref name="value" />; or <see langword="null" /> if no such constant is found.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If multiple enumeration members have the same underlying value, the <xref:System.Enum.GetName%2A> method guarantees that it will return the name of one of those enumeration members. However, it does not guarantee that it will always return the name of the same enumeration member. As a result, when multiple enumeration members have the same value, your application code should never depend on the method returning a particular member's name.
## Examples
The following example illustrates the use of `GetName`.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/enumgetname/CPP/EnumGetName.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Enum/GetName/EnumGetName.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/GetName/EnumGetName.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/enumgetname/VB/EnumGetName.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">
<paramref name="enumType" /> or <paramref name="value" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="enumType" /> is not an <see cref="T:System.Enum" />.
-or-
<paramref name="value" /> is neither of type <paramref name="enumType" /> nor does it have the same underlying type as <paramref name="enumType" />.</exception>
<exception cref="T:System.InvalidOperationException">.NET 8 and later versions: <paramref name="enumType" /> is a Boolean-backed enumeration type.</exception>
</Docs>
</Member>
<Member MemberName="GetName<TEnum>">
<MemberSignature Language="C#" Value="public static string? GetName<TEnum> (TEnum value) where TEnum : struct;" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig string GetName<struct .ctor (class System.Enum, class System.ValueType) TEnum>(!!TEnum value) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Enum.GetName``1(``0)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function GetName(Of TEnum As Structure) (value As TEnum) As String" />
<MemberSignature Language="F#" Value="static member GetName : 'Enum -> string (requires 'Enum : struct)" Usage="System.Enum.GetName value" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename TEnum>
 where TEnum : value class static System::String ^ GetName(TEnum value);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-8.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(0)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="TEnum">
<Constraints>
<ParameterAttribute>DefaultConstructorConstraint</ParameterAttribute>
<ParameterAttribute>NotNullableValueTypeConstraint</ParameterAttribute>
<BaseTypeName>System.Enum</BaseTypeName>
<BaseTypeName>System.ValueType</BaseTypeName>
</Constraints>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="value" Type="TEnum" Index="0" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0" />
</Parameters>
<Docs>
<typeparam name="TEnum">The type of the enumeration.</typeparam>
<param name="value">The value of a particular enumerated constant in terms of its underlying type.</param>
<summary>Retrieves the name of the constant in the specified enumeration type that has the specified value.</summary>
<returns>A string containing the name of the enumerated constant in <typeparamref name="TEnum" /> whose value is <paramref name="value" />; or <see langword="null" /> if no such constant is found.</returns>
<remarks>To be added.</remarks>
<exception cref="T:System.InvalidOperationException">.NET 8 and later versions: <typeparamref name="TEnum" /> is a Boolean-backed enumeration type.</exception>
</Docs>
</Member>
<Member MemberName="GetNames">
<MemberSignature Language="C#" Value="public static string[] GetNames (Type enumType);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig string[] GetNames(class System.Type enumType) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Enum.GetNames(System.Type)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function GetNames (enumType As Type) As String()" />
<MemberSignature Language="F#" Value="static member GetNames : Type -> string[]" Usage="System.Enum.GetNames enumType" />
<MemberSignature Language="C++ CLI" Value="public:
 static cli::array <System::String ^> ^ GetNames(Type ^ enumType);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName Language="C#">[System.Runtime.InteropServices.ComVisible(true)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.InteropServices.ComVisible(true)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String[]</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="enumType" Type="System.Type" />
</Parameters>
<Docs>
<param name="enumType">An enumeration type.</param>
<summary>Retrieves an array of the names of the constants in a specified enumeration.</summary>
<returns>A string array of the names of the constants in <paramref name="enumType" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The elements of the return value array are sorted by the binary values of the enumerated constants (that is, by their unsigned magnitude). The following example provides displays information about the array returned by the <xref:System.Enum.GetNames%2A> method for an enumeration that includes a negative, zero, and a positive value.
:::code language="csharp" source="~/snippets/csharp/System/Enum/GetNames/getnames1.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/GetNames/getnames1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.getnames/vb/getnames1.vb" id="Snippet1":::
If there are enumerated constants with same value, the order of their corresponding names is unspecified.
## Examples
The following example illustrates the use of the <xref:System.Enum.GetNames%2A> method.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/enumgetnames/CPP/EnumGetNames.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Enum/GetNames/EnumGetNames.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/Enum/GetNames/EnumGetNames.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/enumgetnames/VB/EnumGetNames.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">
<paramref name="enumType" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="enumType" /> parameter is not an <see cref="T:System.Enum" />.</exception>
<exception cref="T:System.InvalidOperationException">.NET 8 and later versions: <paramref name="enumType" /> is a Boolean-backed enumeration type.</exception>
</Docs>
</Member>
<Member MemberName="GetNames<TEnum>">
<MemberSignature Language="C#" Value="public static string[] GetNames<TEnum> () where TEnum : struct;" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig string[] GetNames<struct .ctor (class System.Enum, class System.ValueType) TEnum>() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Enum.GetNames``1" />
<MemberSignature Language="VB.NET" Value="Public Shared Function GetNames(Of TEnum As Structure) () As String()" />
<MemberSignature Language="F#" Value="static member GetNames : unit -> string[] (requires 'Enum : struct)" Usage="System.Enum.GetNames " />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename TEnum>
 where TEnum : value class static cli::array <System::String ^> ^ GetNames();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String[]</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="TEnum">
<Constraints>
<ParameterAttribute>DefaultConstructorConstraint</ParameterAttribute>
<ParameterAttribute>NotNullableValueTypeConstraint</ParameterAttribute>
<BaseTypeName>System.Enum</BaseTypeName>
<BaseTypeName>System.ValueType</BaseTypeName>
</Constraints>
<Attributes>
<Attribute FrameworkAlternate="net-8.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters />
<Docs>
<typeparam name="TEnum">The type of the enumeration.</typeparam>
<summary>Retrieves an array of the names of the constants in a specified enumeration type.</summary>
<returns>A string array of the names of the constants in <typeparamref name="TEnum" />.</returns>
<remarks>To be added.</remarks>
<exception cref="T:System.InvalidOperationException">.NET 8 and later versions: <typeparamref name="TEnum" /> is a Boolean-backed enumeration type.</exception>
</Docs>
</Member>
<Member MemberName="GetTypeCode">
<MemberSignature Language="C#" Value="public TypeCode GetTypeCode ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance valuetype System.TypeCode GetTypeCode() cil managed" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<MemberSignature Language="DocId" Value="M:System.Enum.GetTypeCode" />
<MemberSignature Language="VB.NET" Value="Public Function GetTypeCode () As TypeCode" />
<MemberSignature Language="F#" Value="abstract member GetTypeCode : unit -> TypeCode
override this.GetTypeCode : unit -> TypeCode" Usage="enum.GetTypeCode " FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<MemberSignature Language="C++ CLI" Value="public:
 virtual TypeCode GetTypeCode();" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance valuetype System.TypeCode GetTypeCode() cil managed" FrameworkAlternate="netcore-2.0" />
<MemberSignature Language="F#" Value="member this.GetTypeCode : unit -> TypeCode" Usage="enum.GetTypeCode " FrameworkAlternate="netcore-2.0" />
<MemberSignature Language="C++ CLI" Value="public:
 TypeCode GetTypeCode();" FrameworkAlternate="netcore-2.0" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">M:System.IConvertible.GetTypeCode</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.TypeCode</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns the type code of the underlying type of this enumeration member.</summary>
<returns>The type code of the underlying type of this instance.</returns>
<remarks>To be added.</remarks>
<exception cref="T:System.InvalidOperationException">The enumeration type is unknown.</exception>
<altmember cref="M:System.Enum.GetUnderlyingType(System.Type)" />
</Docs>
</Member>
<Member MemberName="GetUnderlyingType">
<MemberSignature Language="C#" Value="public static Type GetUnderlyingType (Type enumType);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.Type GetUnderlyingType(class System.Type enumType) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Enum.GetUnderlyingType(System.Type)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function GetUnderlyingType (enumType As Type) As Type" />
<MemberSignature Language="F#" Value="static member GetUnderlyingType : Type -> Type" Usage="System.Enum.GetUnderlyingType enumType" />
<MemberSignature Language="C++ CLI" Value="public:
 static Type ^ GetUnderlyingType(Type ^ enumType);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>