Home > Net >  About the List collection to a single attribute assignment problem
About the List collection to a single attribute assignment problem

Time:12-09

Suppose I have a class
 
Public class A
{
Public string Id {get; The set; }
Public string Name {get; The set; }
Public string Num {get; The set; }
}


Now I have two List collection
 
List List1=new List (a);
List
List2=new List (a);

I want to put the Num list2 assigned to list1 of Num
Because of the large amount of data I don't want to use the loop to assignment

Is there a way to one-time give a property assignment

Help bosses

CodePudding user response:

Don't have to cycle to assignment because
1. The large amount of data
2. I want to perform this operation is very frequently

So I'm thinking of any non circular way of assignment

CodePudding user response:

Don't know if the Copy can meet your demand

CodePudding user response:

Junction post, don't you want to reply, programmers to abide by the logic, not complying with a garden all day tell you "attack"

Circulation, immortal didn't save, we can only say that the hash lookup than list the find fast

But absolutely can't say that, I will not cycle, because the update, you need to do both Microsoft and IBM need cycle, can only say that they can use index, B tree quickly locate records, rather than their circulation

CodePudding user response:

If you say you are replaced with l2 directly L1, let's say you directly L1=l2
If you say L1 + L2 linq Concat method directly, it is good to connect directly to the two

From the way you ask us that you're actually to update, left the join, or update by such key

Even if we use linq to write, he must be within the same cycle, set operations, set operations, and difference and complement, the operation is not cycle?

The only thing we can suggest is to use a dictionary, use hash alternative List1, in order to reduce the consumption, find and list2 cycle is inevitable

CodePudding user response:

reference 4 floor wanghui0380 response:
if you say you are replaced with l2 directly L1, let's say you directly L1=l2
If you say L1 + L2 linq Concat method directly, it is good to connect directly to the two

From the way you ask us that you're actually to update, left the join, or update by such key

Even if we use linq to write, he must be within the same cycle, set operations, set operations, and difference and complement, the operation is not cycle?

The only thing we can suggest is to use a dictionary, use hash alternative List1, in order to reduce the consumption, find and list2 cycle inevitably


That in addition to the for loop foreach both cycle to assign a value can be the way you offer me other assignment linq can write

CodePudding user response:

 
Var result=the from x in list1
Join in y list2
On x.I d equals y.I d
Into temp
The from z in temp. DefaultIfEmpty ()
Select new A {Id=x.I d, Name=x.N ame, Num=(z==null)? X.N um: z.N um};
  •  Tags:  
  • C#
  • Related