jeudi 8 mars 2018

Appending a string to a list where the list is one of 2 lists in a tuple in a dictionary. C#

I have declared a dictionary "teDict" where each value is a Tuple containing 2 lists.

Dictionary<string, Tuple<List<string>, List<string>>> teDict = new Dictionary<string, Tuple<List<string>, List<string>>>();

I want to append a string from my DataTable to one of the lists depending on another DataTable value.

So far I have the following code that doesn't seem to work:

foreach (DataRow DR in MainData.DataTable.Rows){
                if (DR["123"] == "LC"){
                    if (teDict.ContainsKey(DR["CSN"] + "~" + DR["AA2"])){
                        if (DR["Gender"] == "Male"){
                            teDict[DR["CSN"] + "~" + DR["AA2"]].item1.add(DR["PID"]);
                        }
                    }
                }                                                       
            }
        }

I am getting the below error:

 'System.Tuple<System.Collections.Generic.List<string>,System.Collections.Generic.List<string>>' does not contain a definition for 'item1' and no extension method 'item1' accepting a first argument of type
 'System.Tuple<System.Collections.Generic.List<string>,System.Collections.Generic.List<string>>' could be found (are you missing a using directive or an assembly reference?)

Aucun commentaire:

Enregistrer un commentaire