Is foreach purely “syntactic sugar”?

前端 未结 5 1408
南旧
南旧 2020-12-06 10:32

The compiler compiles a foreach loop into something like a for loop when the foreach is used with an array. And the compiler compile

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 10:54

    It's purely syntactic sugar in that you could obtain the same behaviour without it, yes. Many other things are the same... for, while etc... To misquote Archimedes: "Give me if and goto, and I will move the code..."

    No, the CLR doesn't have any concept of foreach.

提交回复
热议问题