?
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
Medium Priority
?
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
thepanch earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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