This question has long been interested in: is there a difference (in terms of performance) between 2 code fragments?
1st option
XDocument xmlDoc = XDocument.Load("File.xml"); var nodes = xmlDoc.DescendantNodes(); // возвращает IEnumerable<XNode> foreach (XNode node in nodes) { //код } 2nd option
XDocument xmlDoc = XDocument.Load("File.xml"); foreach (XNode node in xmlDoc.DescendantNodes()) { //код } I can assume that foreach works with an enumerator and there is no difference here, although I may be wrong, so please explain.
And another question: if you declare a variable in a loop, will it be updated with each iteration? For example, a temporary variable needed to store intermediate values.
for(int i=0;i<N;i++) { int tmp; // для временного хранения в процессе вычислений // некая логика } Or do it like this:
int tmp; // для временного хранения в процессе вычислений for(int i=0;i<N;i++) { // некая логика } Explain, please.