Multiple values against same condition

RGR

Is there any other way to optimize the below code? I feel the below code is huge for the operations it performs.

if ((currentElement == null ||
    (firstGridRow["Low"].ToString() == string.Empty || 
    firstGridRow["High"].ToString() == string.Empty ||
    firstGridRow["Mean"].ToString() == string.Empty ||
    firstGridRow["StdDev"].ToString() == string.Empty)))
{
    continue;
}

if (newRow.Length != 0)
{
    AddColorList(currentElement, opid, currentLow, "Low", newRow, listCollectionLow);
    AddColorList(currentElement, opid, currentHigh, "High", newRow, listCollectionHigh);
    AddColorList(currentElement, opid, currentMean, "Mean", newRow, listCollectionMean);
    AddColorList(currentElement, opid, currentStdDev, "StdDev", newRow, listCollectionStdDev);
} 
Sergey Kalinichenko

You can use LINQ, like this:

private static readonly string[] AllKeys = new[] {"Low", "High", "Mean", "StdDev"};


if (currentElement == null || ALlKeys.Any(k => gridRow[k].ToString() == string.Empty)) {
     ...
}
if (newRow.Length != 0) {
    foreach (var key in AllKeys) {
        AddColorList(currentElement, opid, currentLow, key, newRow, listCollectionLow);
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL - Comparing against multiple values in the same column?

From Dev

Compare multiple values against the same variable

From Dev

Comparing against multiple values in the same column?

From Dev

Plotting multiple Y values against multiple X values which are different timestamps in matplotlib in the same graph?

From Dev

Check subquery against multiple values

From Dev

Create a new column in pandas based on values in multiple columns and the same condition

From Dev

running the same test against multiple implementations

From Dev

How to use LIKE operator against multiple values

From Dev

Custom .NET ConfigurationSection Validation Against Multiple Values

From Dev

Checking a bash variable against multiple values

From Dev

How to use LIKE operator against multiple values

From Dev

Comparing multiple values against a MySQL table

From Dev

Mongodb multiple OR condition on same key

From Dev

plot multiple y values against one x values in python

From Dev

plot multiple y values against one x values in python

From Dev

inserting multiple values against multiple ids in database table

From Dev

Compare multiple values in one condition

From Dev

Holding multiple values in map on a condition

From Dev

Pythonic way to process multiple for loops with different filters against the same list?

From Dev

Run the same query against multiple tables without dynamic sql

From Dev

How to run the same query against multiple tables in the database

From Dev

Registering multiple components against the same matching lifetime scope

From Dev

Query Nested Object properties against multiple values in elasticsearch

From Dev

Verifying serial number against multiple values in Inno Setup

From Dev

PHP check value against multiple values with OR-operator

From Dev

cannot delete row while comparing column against multiple values

From Dev

Verifying serial number against multiple values in Inno Setup

From Dev

How to filter against multiple values for FK using DjangoFilterBackend

From Dev

Filter/Reject Array of strings against multiple values using underscore

Related Related

  1. 1

    SQL - Comparing against multiple values in the same column?

  2. 2

    Compare multiple values against the same variable

  3. 3

    Comparing against multiple values in the same column?

  4. 4

    Plotting multiple Y values against multiple X values which are different timestamps in matplotlib in the same graph?

  5. 5

    Check subquery against multiple values

  6. 6

    Create a new column in pandas based on values in multiple columns and the same condition

  7. 7

    running the same test against multiple implementations

  8. 8

    How to use LIKE operator against multiple values

  9. 9

    Custom .NET ConfigurationSection Validation Against Multiple Values

  10. 10

    Checking a bash variable against multiple values

  11. 11

    How to use LIKE operator against multiple values

  12. 12

    Comparing multiple values against a MySQL table

  13. 13

    Mongodb multiple OR condition on same key

  14. 14

    plot multiple y values against one x values in python

  15. 15

    plot multiple y values against one x values in python

  16. 16

    inserting multiple values against multiple ids in database table

  17. 17

    Compare multiple values in one condition

  18. 18

    Holding multiple values in map on a condition

  19. 19

    Pythonic way to process multiple for loops with different filters against the same list?

  20. 20

    Run the same query against multiple tables without dynamic sql

  21. 21

    How to run the same query against multiple tables in the database

  22. 22

    Registering multiple components against the same matching lifetime scope

  23. 23

    Query Nested Object properties against multiple values in elasticsearch

  24. 24

    Verifying serial number against multiple values in Inno Setup

  25. 25

    PHP check value against multiple values with OR-operator

  26. 26

    cannot delete row while comparing column against multiple values

  27. 27

    Verifying serial number against multiple values in Inno Setup

  28. 28

    How to filter against multiple values for FK using DjangoFilterBackend

  29. 29

    Filter/Reject Array of strings against multiple values using underscore

HotTag

Archive