c#:如何轻松显示Dictionary <string,int>?

Led*_*Led 1 c# controls dictionary show

我有一个字典,我想在表单中显示.最简单的方法是什么?

我想要显示一个控件,我可以使用int值进行排序.我已经尝试过DataGridView,但没有任何显示,我一定是做错了...

码:

mDataGridView.DataSource = mWordCount; 
/*Where mWordCount is the Dictionary<string, int> but nothing shows up. (It's a forms-app, not a web-app)*/
Run Code Online (Sandbox Code Playgroud)

Rob*_*vey 6

试着mWordCount.ToList()看看会发生什么.

解释是在这里:

DataGridView类支持标准的Windows窗体数据绑定模型.这意味着数据源可以是实现以下接口之一的任何类型:

  • IList接口,包括一维数组.
  • IListSource接口,如DataTableDataSet 类.
  • IBindingList接口,如BindingList<(Of <(T>)>) 类.
  • IBindingListView接口,如BindingSource类.