如何解决错误24运算符'>'不能应用于类型为'string'和'int'的操作数

如何解决错误24运算符'>'不能应用于类型为'string'和'int'的操作数

问题描述:

你好团队,
我遇到以下错误.请帮助
错误24
运算符>"不能应用于类型为"string"和"int"的操作数

字符串密码= customerLoanRecord.Pincode> 0? customerLoanRecord.Pincode.ObjectToString():"Null";

正如在数据库中一样,我根据要求将数据类型保留为Pincode的字符串.

谢谢
Harshal

Hello Team,
I am getting following error.Kindly help
Error 24
operator ''>'' cannot be applied to operands of type ''string'' and ''int''

string pincode = customerLoanRecord.Pincode > 0 ? customerLoanRecord.Pincode.ObjectToString() : "Null";

As in database i kept the datatype as string for Pincode as per requirement.

Thanks
Harshal

string pincode=Convert.ToInt32(customerLoanRecord.Pincode) > 0 ? customerLoanRecord.Pincode.ToString() : string.Empty;



检查是否可行



Check whether this works


您需要先将customerLoanRecord.Pincode转换为整数,然后才能在语句中进行比较.
You need to convert customerLoanRecord.Pincode to integer before comparing it in the statement.
string pincode = Convert.ToInt32(customerLoanRecord.Pincode) > 0 ? customerLoanRecord.Pincode.ObjectToString() : "Null";


string pincode =  Convert.ToInt16( customerLoanRecord.Pincode) > 0 ? customerLoanRecord.Pincode.ObjectToString() : "Null";