请问怎么写一个为的!=和==

4116646555213 2013-01-27 07:39:35
public static bool operator !=(var a,var b)
{
//怎么判断是否为空值???

}
...全文
172 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
blue_apple2006 2013-01-28
  • 打赏
  • 举报
回复
什么东西啊,看不懂。 是重载吗? 重载!=? 这代码能编译吗?
threenewbee 2013-01-28
  • 打赏
  • 举报
回复
if (a != default(类型))
threenewbee 2013-01-28
  • 打赏
  • 举报
回复
引用 3 楼 q730333782 的回复:
引用 1 楼 hjywyj 的回复:C# code ? 12345678 class stu { public int id { get; set; } public static bool operator !=(stu a, stu b) { ……
告诉你了 if (a == default(类型))
路边一青蛙 2013-01-28
  • 打赏
  • 举报
回复


 public static bool operator(var a,var b)
 {
   if(a!= 1 && b != 2){
      return false;}
   else {return true;}

 } 
zhujiazhi 2013-01-28
  • 打赏
  • 举报
回复
if(!(a is object)) { }
  • 打赏
  • 举报
回复
这啥写法啊,第一次看到
4116646555213 2013-01-27
  • 打赏
  • 举报
回复
引用 1 楼 hjywyj 的回复:
C# code ? 12345678 class stu { public int id { get; set; } public static bool operator !=(stu a, stu b) { return a.id != b.id; ……
如果是!=null,会出现未实例化错误
threenewbee 2013-01-27
  • 打赏
  • 举报
回复
public static bool operator !=(var a,var b) { //怎么判断是否为空值??? } 这个代码本身就不能编译,var不能放在函数参数中。 再说,这代码判断的是不等,不是是不是空。 如果是Nullable<T>,或者引用类型才可以判断是否为空。 方法是 if (a == default(类型)) // 空
  • 打赏
  • 举报
回复
 class stu
        {
            public int id { get; set; }
            public static bool operator !=(stu a, stu b)
            {
                return a.id != b.id;
            }
        }

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧