Русские видео

Сейчас в тренде

Иностранные видео




Если кнопки скачивания не загрузились НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием, пожалуйста напишите в поддержку по адресу внизу страницы.
Спасибо за использование сервиса savevideohd.ru



C# Yield Statements Explained Simply: A Beginner's Guide

#coding #codingbootcamp #softwaredeveloper Enter to win free tuition! Enter below! https://startuphakk.com/start-now/?v=... GitHub Repo: https://github.com/slthomason/Startup... C# offers a wide range of tools to make your code shorter, faster and more efficient. Yield statement is one of them, although we tend to forget about it or perhaps don’t know how to use it, it offers great improvement to your code. Throughout this article, we will understand what C# has to offer with this statement and how we can use it. What does a Yield Return return ? Yield return returns the interface IEnumerator or IEnumerable that allows us to iterate over the result using foreach or applying LINQ to the result. The yield statement in C# informs the complier that this block of code is an iterator block. An iterator block aims to produce a sequence of values ​​of the same type. The type of the returned values ​​is called yield type. When the iterator block returns an IEnumerable or an IEnumerator, the yield type is object. When the iterator block returns an IEnumerable or an IEnumerator, the yield type is T. Yield in C# allows us to do 2 things : Custom iteration If I say write me a method that takes a collection of integers as parameters and returns only values above 5. Here we got rid of the intermediate list and we don’t have to iterate through both lists to print results so we improved ressrouce usage and we made the code shorter and easier to maintain. Statefull iteration If I say write me a method that takes returns running total of a list of integers. Here the Yield returns the calculated total each time it’s changed and keeps it state for the next calculation.

Comments