Question : 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.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
public const string cstrDateTime = typeof(System.DateTime).ToString();


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

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

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

Answer : 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

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
Random Solutions  
 
programming4us programming4us