C# Sortable collection which allows duplicate keys

前端 未结 16 2160
旧巷少年郎
旧巷少年郎 2020-11-28 10:06

I am writing a program to set a sequence in which various objects will appear in report. The sequence is the Y position (cell) on Excel spreadsheet.

A demo part of co

16条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 10:51

    Linq.Lookup is cool and all, but if your target is to simply loop over the "keys" while allowing them to be duplicated you can use this structure:

    List> FieldPatterns = new List>() {
       new KeyValuePair("Address","CommonString"),
       new KeyValuePair("Username","UsernamePattern"),
       new KeyValuePair("Username","CommonString"),
    };
    

    Then you can write:

    foreach (KeyValuePair item in FieldPatterns)
    {
       //use item.Key and item.Value
    }
    

    HTH

提交回复
热议问题