Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unusual String type code in System.TypeCode enum

Tags:

string

c#

In the .NET System.TypeCode enum, the values are as follows:

public enum TypeCode {
  ...
  Double=14,
  Decimal=15,
  DateTime=16,
  String=18,
  }

String equals 18.. Why not 17? Where is the logic?

like image 345
Ivan Yuzafatau Avatar asked Feb 04 '26 06:02

Ivan Yuzafatau


1 Answers

You can assign any number (integer in your case) in any order to enum elements. If value is not assigned explicitely, then by default first value will be 0. All other values which not assigned exmplicitely will increment previous element's value by one:

public enum TypeCode 
{
   Double = 42,
   Decimal, // 43
   DateTime = 0,
   String = 18  
}

UPDATE

Why System.TypeCode has value 17 missing - because there used to be TimeSpan type, but it was removed.

like image 178
Sergey Berezovskiy Avatar answered Feb 05 '26 23:02

Sergey Berezovskiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!