两个实体之间的比较 [英] Comparison between two entities

查看:83
本文介绍了两个实体之间的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在为我的设备使用课程:



hello,
I'm using a class for my equipemnts:

public class EQUentity
    {
        public int ID_EQU { get; set; }
        public string CODE_EQU { get; set; }
        public string DESIGNATION_EQU { get; set; }
    }



然后我创建了两个实体:


then I create two entities:

EQUentity EQU1 = new EQUentity 
EQUentity EQU2 = new EQUentity

EQU1.ID_EQU = ....;
...

EQU2.ID_EQU = ....;
......



现在如何控制两个实体是否==

你能帮忙吗?我有一个CLASS女巫扫描权利的元素进行这种控制?



像这样:




Now how to control if the two entities are == or not?
Can you help me with a CLASS witch scans the elements of the entitiy to do this control?

Like this:

public class compare(EQUentity E1, EQUentity E2)
    {
        .....
        ....
    }







最好的问候




Best regards

推荐答案

Equals()上阅读以下内容:http://msdn.microsoft.com/en-us/library/ms173147%28v=vs .80%29.aspx [ ^ ]
Read the following on Equals() : http://msdn.microsoft.com/en-us/library/ms173147%28v=vs.80%29.aspx[^]


一个小例子:



A little example for you:

if(EQU1.ID_EQU.Equals(EQU2.ID_EQU))
{
    //Logic here
}


使用Object.Equals方法(对象)来比较c#中的对象。



转到下面的链接,它将帮助您了解Object.Equals方法。



http://msdn.microsoft.com/en-us/library/bsc2ak47。 aspx



你必须在你的班级中重写equals方法。



Use Object.Equals Method (Object) to compare to object in c#.

Go To Below Link, It will help you to understand Object.Equals method.

http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx

You have to override equals method in your class.

public override bool Equals(object obj)
      {
          EQUentity equOBJ = obj as EQUentity;
          if (equOBJ == null)
          {
              return false;
          }
          else
          {
              if (ID_EQU == equOBJ.ID_EQU && CODE_EQU.Equals(equOBJ.CODE_EQU) && DESIGNATION_EQU.Equals(equOBJ.DESIGNATION_EQU))
              {
                  return true;
              }
              else
              {
                  return false;
              }
          }
      }


这篇关于两个实体之间的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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