Useful alternative control structures?

后端 未结 28 1314
礼貌的吻别
礼貌的吻别 2021-01-30 02:20

Sometimes when I am programming, I find that some particular control structure would be very useful to me, but is not directly available in my programming language. I think my

28条回答
  •  温柔的废话
    2021-01-30 03:05

    I propose the "then" operator. It returns the left operand on the first iteration and the right operand on all other iterations:

    var result = "";
    foreach (var item in items) {
        result += "" then ", ";
        result += item;
    }
    

    in the first iteration it adds "" to the result in all others it adds ", ", so you get a string that contains each item separated by commas.

提交回复
热议问题