简体   繁体   中英

How to check if the variable is a String

I have a simple problem,

dtERP value = 2885,78,89,78A;

for (int i = 0; i < dtERP.Rows.Count; i++)
{
    for (int j = 0; j < dtERP.Columns.Count; j++)
    {
        object field = dtERP.Rows[j]["QTY"];
        if (field != int)
        {

        }
    }
}

How can I validate my field if the value is string?

You can use the is operator. Something like this:

if(field is string)

您可以在变量/实例上执行.GetType()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM