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 11
HuaMinChenBusiness AnalystAsked:
Who is Participating?
Jacques Bourgeois (James Burger)Connect With a Mentor 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.
Monica PSoftware DeveloperCommented:
Are you checking like this ?

int i = 0;
// Prints True for any value of i
Console.WriteLine(i.GetType() == typeof(int));
HuaMinChenBusiness AnalystAuthor 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?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.