Other ways to deal with “loop initialization” in C#

前端 未结 9 771
陌清茗
陌清茗 2020-12-24 07:22

To start with I\'ll say that I agree that goto statements are largely made irrelevant by higher level constructs in modern programming languages and shouldn\'t be used when

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 08:07

    You are already willing to give up on foreach. So this ought to be suitable:

            using (var enumerator = array.GetEnumerator()) {
                if (enumerator.MoveNext()) {
                    for (;;) {
                        append(enumerator.Current);
                        if (!enumerator.MoveNext()) break;
                        append(delimiter);
                    }
                }
            }
    

提交回复
热议问题