首页 > 解决方案 > How can I sort a dictionary by an array?

问题描述

I get the PDF metadatas using itextsharp as follows:

var pdf = new PdfReader(__PDF_PATH__);
var main = new[] { "Title", "Subject", "Creator", "Author", "Producer", "Keywords", "ModDate", "CreationDate" };
var metadatas = pdf.Info; // returns Dictionary<string, string> metadatas

The keys of the dictionary are as in the main array. I want to sort the dictionary's keys according to the given main array. But I did not manage.

标签: c#sortingdictionaryitext

解决方案


您可以在此处查看此答案: 根据键对字典进行排序

或者您可以在此处查看此方法: https ://www.dotnetperls.com/sort-dictionary

但基本上你不能在字典中做到这一点。您可以转换为其他数据结构。


推荐阅读