Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

primitive types enum - does it exist

I need to provide a user a list of all primitive types available and was wondering if there is an Enum in the .net library that has all primitive types, so that I don't have to build one.

like image 413
epitka Avatar asked Dec 01 '09 14:12

epitka


People also ask

Is enum primitive type Javascript?

Enums are reference types, in that they can have methods and can be executed from command line as well , if they have main method.

Is enum primitive type C#?

What is Enum in C#? C# enum is a value type with a set of related named constants often referred as an enumerator list. The C# enum keyword is used to declare an enumeration. It is a primitive data type, which is user-defined.

How do you know if a type is primitive?

Approach 1: In this approach, we check the type of the value using the typeof operator. If the type of the value is 'object' or 'function' then the value is not primitive otherwise the value is primitive. But the typeof operator shows the null to be an “object” but actually, the null is a Primitive.

Is an enum a reference type?

Enum is a reference type, but any specific enum type is a value type. In the same way, System. ValueType is a reference type, but all types inheriting from it (other than System.


1 Answers

Not an enum, but:

var primitives = typeof(int).Assembly.GetTypes()
       .Where(type => type.IsPrimitive).ToArray();
like image 154
Marc Gravell Avatar answered Sep 29 '22 05:09

Marc Gravell