Timujin
Timujin

Reputation: 181

Copy elements of list to new list

I have a structure:

public struct rawData {

    public string recType;          
    public string ncmCode;         
    public string depotNo;         
    public string accNo;              
    public string kVK;             
    public string callPut;         
    public string quanSetUnset;   
    public string abbNameOTC;  
}

public List<rawData> myData = new List<rawData>();
rawData tempRawData = new rawData();

into which I import data to from csv.

My question is, depeding on accNo, how can I copy just specific "rows" into a new list of the same structure.

I can loop through the list

if (account == "xxxxx") {
    for (int i = 0; i < myData.Count; i++) {
        if (myData[i].accNo == account) {
            myData.CopyTo(acc85RawD, i);
        }
    }
}

Im using the copyto but its wrong as that copies to a array, the index i, i need it to copy all elements of index i to a new list....

any help? thanks

Upvotes: 0

Views: 128

Answers (1)

bazz
bazz

Reputation: 613

The projection in LINQ might help..

myData.Where(i=>i.accNo==account).Select(i=>new rawData{recType=i.recType,..});

Upvotes: 3

Related Questions