Question… what is more efficient. [string] != “” && [string] != “” or ![List].Contains()?

I only want to refresh the data on the screen if the user has selected anything other then three specific values… these values are strings because they were user entered.

My question is, which code is more efficient?

string userValue_Lower = DataGrid.GetCellValue().ToLower(); if (userValue_Lower != "value1" && userValue_Lower != "value2" && userValue_Lower != "value3") { /*do stuff*/ } 

or (the method I prefer due to cleaner looking code)

string userValue_Lower = DataGrid.GetCellValue().ToLower(); List<string> noRefreshValues = new List<string>() { "value1", "value2", "value3" } if(!noRefreshValues.Contains(userValue_Lower)) { /*do stuff*/ } 

But I was just curious if there was a difference in efficacy in the code. I assume Contains is faster… but I don’t really know. I’m kind of a one-man team over here so I figured I would ask you guys.

submitted by /u/ihad2manytacos
[link] [comments]

Leave a Reply