[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

Problem with the part

Hi,
While str1 is having 5 inside, I believe it should not go to the codes under 2nd if-line below. But it does. why?
            string str1 = tb_ite.Text;
            if (tb_ite.Text.Trim() != "")
            {
                if ((!(str1.GetType() == typeof(int))) && (!(str1.GetType() == typeof(double))) && (!(str1.GetType() == typeof(long))) && (!(str1.GetType() == typeof(short))) && (!(str1.GetType() == typeof(float))))
                {
                    ...

Open in new window

0
HuaMinChen
Asked:
HuaMinChen
2 Solutions
 
AndyAinscowCommented:
str1.GetType() will ALWAYS return the same type - a string because str1 is a string variable.

Your code is very likely not what you want to do.
0
 
tipsybroomCommented:
str1.GetType() returns string

If you want to know if it is a numeric value have a look at:
http://www.codeproject.com/Articles/16329/C-Equivalent-of-VB-s-IsNumeric
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now