Home > Back-end >  Select different objects from two collections in C# LINQ
Select different objects from two collections in C# LINQ

Time:08-18

I have the following class:

struct UserRecord
{
    //--- common settings
    int               login;                      // login
    int               leverage;                   // leverage
    int               enable;                     // enable
}

And I have two lists:

List<UserRecord> base_data = new List<UserRecord();

base_data.add(new UserRecord(){login = 1, leverage = 1000, enable = 0});
base_data.add(new UserRecord(){login = 2, leverage = 100, enable = 0});
base_data.add(new UserRecord(){login = 3, leverage = 10, enable = 1});
base_data.add(new UserRecord(){login = 4, leverage = 10000, enable = 0});

List<UserRecord> snapshot_data= new List<UserRecord();

snapshot_data.add(new UserRecord(){login = 1, leverage = 1000, enable = 1});
snapshot_data.add(new UserRecord(){login = 2, leverage = 100, enable = 0});
snapshot_data.add(new UserRecord(){login = 3, leverage = 10, enable = 1});
snapshot_data.add(new UserRecord(){login = 4, leverage = 10000, enable = 1});

My goal is to filter the records, and get the two records in a new list, that are with different fields, in this case only field 'enable' is different.

var filtered_data = new List<UserRecord>(); // here records with login 1 and 4 should go.

Do you have any suggestions ?

CodePudding user response:

You may look for enter image description here

  • Related