I have a switch statement to compare a datagrid column type to a constant. How do I assign a DateTime type to a constant. I tried using type of but that is run time

Please see attached code.  Constant declaration is not right because it is at runtime.
public const string cstrDateTime = typeof(System.DateTime).ToString();

switch (ColomnType)
                            case cstrInt:
                                // Output Integers as numbers
                                msoStyle = "";

                            case cstrDateTime:
                                // Output dates as MM/dd/yyyy
                                msoStyle = "mso-number-format: mm\\/dd\\/yy";

                                // Output other values as string
                                msoStyle = "mso-number-format: \\@";

Open in new window

Who is Participating?
thepanchConnect With a Mentor Commented:
object cstrDateTime = new DateTime(); //this line set the type DateTime to the object

            if (cstrDateTime.GetType().Name.ToString()=="DateTime") //compare the Type of the object
            MessageBox.Show(cstrDateTime.GetType().ToString()); //just do something if its true.

I hope it helps
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.