gs gs108 Reflections, Multithreaded Programming, Collection Classes and Mathematical Functions - Iterators - Quiz No.1
gs gs108 CSharp Quiz
This quiz belongs to book/course code gs gs108 CSharp of gs organization. We have 110 quizzes available related to the book/course CSharp. This quiz has a total of 9 multiple choice questions (MCQs) to prepare and belongs to topic Reflections, Multithreaded Programming, Collection Classes and M. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
class MyClass { char[] chrs = { 'A', 'B', 'C', 'D' }; public System.Collections.IEnumerator GetEnumerator() { foreach (char ch in chrs) yield return ch; } } class Program { static void Main(string[] args) { MyClass mc = new MyClass(); foreach (char ch in mc) Console.Write(ch + " "); Console.WriteLine(); Console.ReadLine(); } }
public System.Collections.IEnumerator GetEnumerator() { foreach (char ch in chrs) yield return ch; }
public System.Collections.IEnumerator GetEnumerator() { foreach (char ch in chrs) yield return ch; }
class MyClass { char chrs = 'A' ; public IEnumerator GetEnumerator() { for (int i = 20; i >=0; --i) if (i == 10) yield break; 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(); } }
class MyClass { int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; public IEnumerator GetEnumerator() { for (int i = 0; i < 20; i++) { if (a[i] % 2 == 0) yield return (int)(a[i]); } } } class Program { static void Main(string[] args) { MyClass mc = new MyClass(); foreach (int i in mc) Console.Write(i + " "); Console.WriteLine(); Console.ReadLine(); } }
class MyClass { char ch = 'A'; public IEnumerable MyItr(int end) { for (int i = 0 ;i < end ;i++) yield return (char)(ch + i); } public IEnumerable MyItr(int begin, int end) { for (int i = begin ;i < end ;i++) yield return (char)(ch + i); } } class Program { static void Main(string[] args) { MyClass mc = new MyClass(); Console.WriteLine("Iterate the first 7 letters:"); foreach (char ch in mc.MyItr(7)) Console.Write(ch + " "); Console.WriteLine("n"); Console.WriteLine("Iterate letters from F to L:"); foreach (char ch in mc.MyItr(7, 12)) Console.Write(ch + " "); Console.WriteLine(); Console.ReadLine(); } }
Iterate the first 7 letters: A B C D E F G Iterate letters from F to L: G H I J K L
Iterate the first 7 letters: A B C D E F G Iterate letters from F to L: H I J K L
class MyClass { char ch = 'A'; int e = 4; int k = 9; int z = 6; public IEnumerator GetEnumerator() { for (int i = 0; i < 26; i++) { if (i == e*k /z) yield break; yield return (int)(ch + i); } } } class Program { static void Main(string[] args) { MyClass mc = new MyClass(); foreach(int ch in mc) Console.Write(ch + " "); Console.WriteLine(); Console.ReadLine(); } }