简体   繁体   中英

Fastest way to access cell value in bound DataGridView

I have a DataGridView that is bound to a BindingList of objects and I need to access the value of a particular cell in each row as quickly as possible. Is it faster to do:

if (((ObjectType)row.DataBoundItem).StringProperty != string.Empty)
{
}

...or...

if (row.Cells["STRINGPROPERTY"].Value != string.Empty)
{
}

Or is there another way that's faster than both of these?

There's a lot of way to check the value with if is empty or null but from your main question you can go and try to Benchmarking method calls in C#

  1. String.IsNullOrEmpty
  2. String.IsNullOrWhiteSpace
  3. Best way to check if column returns a null value (from database to .net application)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM