Solved

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

Posted on 2010-08-25
1
244 Views
Last Modified: 2012-05-10
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 = "";

                                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;

                        }

Open in new window

0
Comment
Question by:MichBman
1 Comment
 
LVL 4

Accepted Solution

by:
thepanch earned 500 total points
ID: 33525058
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why, and when, to use Windows Workflow 1 32
Data Saving 5 56
VB.NET HttpWebRequest 12 58
Coding C# in Linux 8 34
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now