当我运行此代码时出现错误 [英] when i run this code error occurs

查看:87
本文介绍了当我运行此代码时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  if (dateofbirth.Year.ToString()!=  1900 
SendSMS(txt_DOB.Text.Trim());
else
if (Weddingday.Year.ToString()!= 1900
SendSMS(txt_wedding.Text.Trim());




$ b当我运行时,$ b形成以上内容我显示错误消息如下;



运算符''!=''不能应用于''string'类型的操作数'和''int''。



请更正我的代码并发送正确的代码。





请帮帮我。

解决方案

尽管ridoy提出的解决方案可行,但这真的不是一个好主意:你正在转换一个整数到一个字符串只是为了将它与一个整数常量的字符串版本进行比较!直接使用整数:

  if (dateofbirth.Year!=  1900 
SendSMS(txt_DOB.Text.Trim());
其他 如果(Weddingday.Year!= 1900
SendSMS(txt_wedding.Text.Trim());

内存更快,效率更高,更容易阅读!


试试这个..

 如果(dateofbirth.Year.ToString()! =   1900
SendSMS(txt_DOB.Text.Trim());
else if (Weddingday.Year.ToString()!= 1900
SendSMS(txt_wedding.Text.Trim());


if(dateofbirth.Year.ToString()!=1900)
    SendSMS(txt_DOB.Text.Trim());
    else
    if(Weddingday.Year.ToString()!=1900)
    SendSMS(txt_wedding.Text.Trim());



form the above when i run i show the error message as follows;

Operator ''!='' cannot be applied to operands of type ''string'' and ''int'' .

please correct my code and send the correct code.


please help me.

解决方案

Although the solution proposed by ridoy will work, it is really not a good idea: you are converting an integer to a string just to compare it to a string version of an integer constant! Use the integers directly:

if(dateofbirth.Year != 1900)
   SendSMS(txt_DOB.Text.Trim());
else if(Weddingday.Year != 1900)
   SendSMS(txt_wedding.Text.Trim());

It''s faster, more efficient in memory, and easier to read!


Try with this..

if(dateofbirth.Year.ToString()!="1900") 
   SendSMS(txt_DOB.Text.Trim());
else if(Weddingday.Year.ToString()!="1900")
   SendSMS(txt_wedding.Text.Trim());


这篇关于当我运行此代码时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆