and foreach



  • Tell me who can explain the use of the masses. Simple language? There's some crazy words in the books. And if you can, too. Simple languageto speak of the operator.

    foreach
    


  • According to MSDN http://msdn.microsoft.com/ru-ru/library/ttw7t8t6.aspx :

    The Operator foreach repeats a group of imported operators for each element of the set or collection of facilities that operate the interface System.Collections. IEnumerable or System.Collections.Generic.IEnumerable(Of T).

    Just an example.

    // Создаем массив и его инициализируем
    string[] fruits = { "apple", "pear", "orange", "mandarin" };
    

    // Проходим подряд по множеству значений массива и присваиваем fruit значение
    // очередного элемента
    foreach (string fruit in fruits) {
    Console.WriteLine(fruit);
    }

    or

    // Или пробегаем индексы от 0 до lenth - 1 и выводим значение элемента по индексу
    for (int i = 0; i++; i < fruits.length) {
    Console.WriteLine(fruits[i]);
    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2