Is it better coding practice to define variables outside a foreach even though more verbose?

前端 未结 12 2209
栀梦
栀梦 2020-12-10 10:39

In the following examples:

  • the first seems more verbose but less wasteful of resources
  • the second is less verbose bu
12条回答
  •  轮回少年
    2020-12-10 11:23

    I generally declare variables as close to their use as scoping allows, which in this case would be your second example. Resharper tends to encourage this style as well.

提交回复
热议问题