What does the yield return statement specify in the following C# code snippet?

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

What does the yield return statement specify in the following C# code snippet?

Post by answerhappygod »

advertisement


var adpushup = window.adpushup || {};
adpushup.que = adpushup.que || [];
adpushup.que.push(function () {
if (adpushup.config.platform === "MOBILE") {
adpushup.triggerAd("90f55663-effd-4105-b1e7-29d86b526544");
} else if ((window.outerWidth <= 768) || (window.outerWidth == 0)) {
adpushup.triggerAd("90f55663-effd-4105-b1e7-29d86b526544");
}
});
public System.Collections.IEnumerator GetEnumerator() { foreach (char ch in chrs) yield return ch; }a) returns the outputb) returns the next object in the collectionc) Both returns the output & returns the next object in the collectiond) none of the mentioned[expand title="View Answer"] Answer: bExplanation: The yield return statement returns the next object in the collection, which in this case is the next character in chrs in the code.[/expand] 5. What does the following C# code snippet specify?<pre lang="csharp" line="1" cssfile="hk1_style">class MyClass{ char chrs = 'A' ; public IEnumerator GetEnumerator() { for (int i = 20; i >=0; --i) yield return (char)((chrs + i)); }}class Program{ static void Main(string[] args) { MyClass mc = new MyClass(); foreach (char ch in mc) Console.Write(ch + " "); Console.WriteLine(); Console.ReadLine(); }}
a) A B C D E F G H I J K L M N O P Q R S T U V
b) Run time error
c) U T S R Q P O N M L K J I H G F E D C B A
d) Compile successfully prints nothing
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!

This topic has 1 reply

You must be a registered member and logged in to view the replies in this topic.


Register Login
 
Post Reply