RUVIDEO
Поделитесь видео 🙏

Using C#'s Yield Keyword

C#'s Yield operator allows you to define enumerable sets which can be dynamically generated and are lazily evaluated. This enables a number of fun things that would be difficult otherwise such as infinite lists. Some other frameworks have also taken advantage of `yield` to power different features like [Unity 3D's Coroutines](https://docs.unity3d.com/Manual/Coroutines.html).

When used in a function or property which returns an `IEnumerable`, yield will provide two features. You may `return` the next value in the set or `break` out of the loop - effectively terminating the set. Values `return`ed from a `yield` keyword are composed into the enumerable set as your code evaluates. Yield statements are evaluated lazily (meaning the function generating the enumerable object is not generated completely before the first element is returned), this means that after returning with `yield` the code in the function will continue from the point it returned from including preserving the state (such as local variable values).

Using these concepts we can create a function which returns all positive integers between 1 and a max value.

```csharp
// Note: you'll need to replace the IEnumerable˂int˃ with correct syntax as well as the ˃= symbol
public static IEnumerable˂int˃ PositiveInts(int max) {
int i = 1;
while(true) {
yield return i++;
if (i ˃= max) {
yield break;
}
}
}
```

* `yield return`: returns the next value in an `IEnumerable`.
* `yield break`: marks the end of the `IEnumerable`.

More information about using `yield` with some other examples is available here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/yield

Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Using C#'s Yield Keyword», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.