【问题标题】:Winforms DataGridView.Rows.Cells[] -> which is faster? Cells[int] or Cells[string]Winforms DataGridView.Rows.Cells[] -> 哪个更快? Cells[int] 或 Cells[string]
【发布时间】:2018-10-25 20:26:44
【问题描述】:


嘿伙计们:)

  dataGridView1.Rows[0].Cells[0] 
                  VS 
  dataGridView1.Rows[0].Cells["Zone"]

你能解释一下哪个更快,为什么?

*请解释一下字符串查找的工作原理。

谢谢!

【问题讨论】:

  • DataGridViewRowCollection 上没有字符串索引器,该代码无法针对System.Windows.Forms.DataGridView 编译另请参阅referencesource.microsoft.com/#System.Windows.Forms/winforms/…
  • 抱歉我做错了 -> Rows[0] 总是 int
  • 我想也许有某种 Dictionary 植入
  • System.Data.DataReader 同时拥有intstring 索引器,也许您的意思是这样的?
  • 是的,但是字符串索引会变慢吗?如果是,会慢多少。我有一个包含 200 行的表,每 100 毫秒更新一次(某些单元格中的值)

标签: c# winforms performance datagridview


【解决方案1】:

如果上面的代码的类型与System.Windows.Forms.DataGridView 不同,或者可能在某处有扩展方法,则上面的代码实际工作的唯一方法。

dataGridView1.Rows[0] 的任何集合的大多数实现都会更快,因为 dataGridView1.Rows["PositionID"] 版本所做的是查找索引,然后完全按照您对 dataGridView1.Rows[0] 所做的操作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多