-1

How to initialize the array of data types in System.Type Datatype

This sample code i am trying

Type[] coltypes = {string, string, string, string, string, string }; 

after I found the solution in this link i am able to understand the problem

Gettype

Solution for this : Type[] coltypes = {typeof(string),typeof(int),typeof(double),typeof(string)};

0

3 Answers 3

5

You need to use typeof() to get the type object for a type:

Type[] coltypes = new Type[] { typeof(string), typeof(int), typeof(double) }; 

Note that using the typeof expression is interpreted by the compiler and gets the type object at compile-time.

Sign up to request clarification or add additional context in comments.

Comments

4

Because string is not System.Type itself. You can use typeof operator to generate it's System.Type.

You can use;

Type[] coltypes = { typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string) }; 

Comments

0

You're missing a comma for one thing,

Type[] coltypes = { typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string) }; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.