三元运算符重叠

Dav*_*vid 3 c# wpf performance ternary-operator

我想知道:这两个版本之间的性能最佳指令是什么:

Background = Application.Current.Resources[condition ? BackgroundName1 : BackgroundName2] as Brush;
Run Code Online (Sandbox Code Playgroud)

和:

Background = condition ? Application.Current.Resources[BackgroundName1] as Brush : Application.Current.Resources[BackgroundName2] as Brush;
Run Code Online (Sandbox Code Playgroud)

有什么不同吗?如果是,哪一个更好?

谢谢

注意:BackgroundName1和2只是字符串

SLa*_*aks 5

第一个更短,更易读.

它也更容易维护.
如果您稍后将其更改为读取其他资源字典,则可能忘记更改第二个字典的后半部分.

第一个也是从同一个字典中读得更清楚.