fork download
  1. using static System.Console;
  2. using System.Collections.Generic;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. var lista = new List<int>() { 1, 2, 3, 4 };
  7. var anterior = 0;
  8. foreach (var item in lista) {
  9. WriteLine($"Soma o atual e anterior { anterior + item }");
  10. anterior = item;
  11. }
  12. }
  13. }
  14.  
  15. //https://pt.stackoverflow.com/q/271540/101
Success #stdin #stdout 0.02s 16004KB
stdin
Standard input is empty
stdout
Soma o atual e anterior 1
Soma o atual e anterior 3
Soma o atual e anterior 5
Soma o atual e anterior 7