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

前端 未结 12 2246
栀梦
栀梦 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条回答
  •  旧时难觅i
    2020-12-10 11:21

    They are both virtually the same as far as performance goes (strings are immutable), but as for readability... I'd say neither is very good. You could easily just do it all within the Console.WriteLine.

    Perhaps you can post the real problem instead of an example?

提交回复
热议问题