mardi 26 octobre 2021

Does C# have any equivalent to Elixir's `cond`?

In Elixir, if I want to check multiple boolean conditions, rather than some ugly mess of if/else logic, I can elegantly do this:

x = cond do
  2 + 2 == 5 ->
    "This will not be true"

  2 * 2 == 3 ->
    "Nor this"

  1 + 1 == 2 ->
    "But this will"
end

with the result that "x" will equal "But this will".

Does C# have anything similar or would I need to use if/else?

Aucun commentaire:

Enregistrer un commentaire