Methods of simplifying ugly nested if-else trees in C#

前端 未结 11 769
野性不改
野性不改 2021-02-02 04:23

Sometimes I\'m writing ugly if-else statements in C# 3.5; I\'m aware of some different approaches to simplifying that with table-driven development, class hierarchy, anonimous m

11条回答
  •  [愿得一人]
    2021-02-02 04:35

    I'm a big fan of the ternary operator which get's overlooked by a lot of people. It's great for assigning values to variables based on conditions. like this

    foobarString = (foo == bar) ? "foo equals bar" : "foo does not equal bar";
    

    Try this article for more info.

    It wont solve all your problems, but it is very economical.

提交回复
热议问题