Problem with DataType

How to resolve this
Error    4    'string' does not contain a definition for 'DataType' and no extension method 'DataType' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)    C:\App16\Default.aspx.cs    64    24    App16

due to this line?

if (!(str1.DataType==typeof(int)))

Open in new window

LVL 12
HuaMin ChenProblem resolverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Monica PSoftware DeveloperCommented:
Are you checking like this ?

int i = 0;
// Prints True for any value of i
Console.WriteLine(i.GetType() == typeof(int));
HuaMin ChenProblem resolverAuthor Commented:
No, I did declare str1 as a string above. How to correct my codes above?
käµfm³d 👽Commented:
What are you trying to do? I don't see the point of comparing a string variable's type to see if it is of type string--it will always be a string. What is your goal here?
Jacques Bourgeois (James Burger)PresidentCommented:
If you are trying to see if the value in a String can be converted to an integer, you can use TryParse on the Integer type:

if ( !( int.TryParse(str1, out int1 ) )) System.Windows.Forms.MessageBox.Show ( "The value in str1 is not an integer" );

If the conversion is possible, int1 will contain the result of the conversion.
Otherwise, int1 will keep its value and the Message will display.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.