Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 查找不同对象并从对象中删除重复项_C#_Asp.net_Linq_.net Core - Fatal编程技术网

C# 查找不同对象并从对象中删除重复项

C# 查找不同对象并从对象中删除重复项,c#,asp.net,linq,.net-core,C#,Asp.net,Linq,.net Core,我对林克很陌生。我已经运行到一个场景中,我需要找到一个与对象不同的对象并删除其他对象。请帮忙。 我试过这样做 var xyz=refereal.GroupBy(i=>i.Select(x=>x.identifier).Distinct().Select(g=>g)) 但它并没有返回不同的值。提前谢谢。 示例对象: { "referral_type": [ { "type": "MOBILE", "invitee": [ {

我对林克很陌生。我已经运行到一个场景中,我需要找到一个与对象不同的对象并删除其他对象。请帮忙。 我试过这样做
var xyz=refereal.GroupBy(i=>i.Select(x=>x.identifier).Distinct().Select(g=>g))
但它并没有返回不同的值。提前谢谢。
示例对象:

{
    "referral_type": [
      {
        "type": "MOBILE",
        "invitee": [
          {
            "identifier": "12345678",
            "name": "Test2",
            "invited_on": "2020-01-29 12:25:46.0",
            "till": {
              "code": "",
              "name": ""
            }
          },
          {
            "identifier": "98765432",
            "name": "Test1",
            "invited_on": "2020-01-29 13:37:36.0",
            "till": {
              "code": "",
              "name": ""
            }
          },
          {
            "identifier": "12345678",
            "name": "Harry Test",
            "invited_on": "2020-01-29 13:55:32.0",
            "till": {
              "code": "",
              "name": ""
            }
          },
          {
            "identifier": "98765432",
            "name": "Harry Test",
            "invited_on": "2020-01-29 13:55:32.0",
            "till": {
              "code": "",
              "name": ""
            }
          }
        ]
      }
    ]
}

所以我想检查不同的标识符,并取第一个不受其他值影响的标识符,类似这样的

{
        "referral_type": [
          {
            "type": "MOBILE",
            "invitee": [
              {
                "identifier": "12345678",
                "name": "Test2",
                "invited_on": "2020-01-29 12:25:46.0",
                "till": {
                  "code": "",
                  "name": ""
                }
              },
              {
                "identifier": "98765432",
                "name": "Test1",
                "invited_on": "2020-01-29 13:37:36.0",
                "till": {
                  "code": "",
                  "name": ""
                }
              }
            ]
          }
        ]
}

您需要实现接口
IEquatable
类“invitee”,因为Dinstinct使用它来比较对象。通过这种方式,我认为您正在比较内存引用。

是否要从json中删除重复项?