c# - 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.
解决方案
您可以在此处查看此答案: 根据键对字典进行排序
或者您可以在此处查看此方法: https ://www.dotnetperls.com/sort-dictionary
但基本上你不能在字典中做到这一点。您可以转换为其他数据结构。
推荐阅读
- python - 使用 Pyinstaller 打包后代码不运行
- memory - Redis hash structure does not make memory efficient as described
- docker - task.Container moving from docker to kubernetes
- spring-boot - Spring.jpa.open-in-view 给出异常
- java - Struts2没有为命名空间[/]和与上下文路径关联的动作名称[]映射的动作[包含文件中的顺序问题]
- ios - 使用后退按钮从 NavigationController 导航到另一个 NavigationController
- php - 使用 PHP 将文件上传到 Amazon S3 存储桶 - 不使用 SDK
- javascript - 当 tabualtor 中的鼠标悬停单元格时,使用 iframe 打开模态(弹出框)
- c# - 无法加载文件或程序集“System.Web.Mvc(1)”或其依赖项之一
- javascript - 如何使用 React 转换组转换文本更改?