Is it better coding practice to define variables outside a foreach even though more verbose?
- 阅读更多 关于 Is it better coding practice to define variables outside a foreach even though more verbose?
In the following examples: the first seems more verbose but less wasteful of resources the second is less verbose but more wasteful of resources (redefines string each loop) Which is better coding practice? First example: using System; using System.Collections.Generic; namespace TestForeach23434 { class Program { static void Main(string[] args) { List<string> names = new List<string> { "one", "two", "two", "three", "four", "four" }; string test1 = ""; string test2 = ""; string test3 = ""; foreach (var name in names) { test1 = name + "1"; test2 = name + "2"; test3 = name + "3"; Console