C# capabilities keep expanding from year to year. New features enrich software development. However, their advantages may not always be so obvious. For example, the good old yield. To some developers, especially beginners, it's like magic - inexplicable, but intriguing. This article shows how yield works and what this peculiar word hides. Have fun reading!
C## capabilities keep expanding from year to year. New features enrich software development. However, their advantages may not always be so obvious. For example, the good old yield. To some developers, especially beginners, it's like magic - inexplicable, but intriguing. This article shows how yield works and what this peculiar word hides. Have fun reading!
The yield keyword is used to build generators of element sequences. These generators do not create collections. Instead, the sequence stores the current state - and moves on to the next state on command. Thus, memory requirements are minimal and do not depend on the number of elements. It's not hard to guess that generated sequences can be infinite.
In the simplest scenario, the generator stores the current element and contains a set of commands that must be executed to get a new element. This is often much more convenient than creating a collection and storing all of its elements.
While there is nothing wrong with writing a class to implement the generator's behavior, yield simplifies creating such generators significantly. You do not have to create new classes - everything works already.
I must point out here that yield is not a feature available exclusively in C#. However, while the concept is the same, in different languages yield may be implemented and used differently. Which is why here's one more reminder that this article talks about yield only in the context of C#.
Attempt this GK Quiz with answers on important events in various months to assess your general knowledge for competitive exams and general knowledge tests.
A Knowledge Based Agent in Artificial Intelligence has two levels: Knowledge Base (KB) and Inference Engine.
In this Video you will learn how to write a CSharp Fibonacci Series Programm. Learn how to use the Fibonacci Sequence in C#. Write a little C# Program to get Fibonacci Numbers. This Fibonacci Series is seen in Nature quite often.
Artificial intelligence has a crucial role to play in modern businesses. Most companies around the world perceive knowledge management as an IT project. AI in knowledge management allows them to unlock knowledge to improve the decision-making process and generate high ROI.
This video is a compilation of my 5 successful videos - 50 C# Interview Questions and Answers and should be seen as interview preparation.