Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

C# MCQ Set 1

1. Assume 2 columns named as Product and Category how can be both sorted out based on first by category and then by product name?
a) var sortedProds = _db.Products.Orderby(c => c.Category)
b) var sortedProds = _db.Products.Orderby(c => c.Category) + ThenBy(n => n.Name)
c) var sortedProds = _db.Products.Orderby(c => c.Category) . ThenBy(n => n.Name)
d) all of the mentioned

View Answer

Answer: c [Reason:] var sortedProds = _db.Products.Orderby(c => c.Category) . ThenBy(n => n.Name).

2. Choose the wrong statement about the LINQ?
a) The main concept behind the linq is query
b) linq makes use of foreach loop to execute the query
c) It is not required that linq should make use of IEnumerable interface
d) None of the mentioned

View Answer

Answer: c [Reason:] LINQ at core is the query.A query specifies what data will be obtained from a data source.Query in linq is executed using foreach loop.In order for a source of data to be used by LINQ, it must implement the IEnumerable interface.

3. Choose the namespace in which the interface IEnumerable is declared?
a) System.Collections
b) System.Collections.Generic
c) Both a & b
d) None of the mentioned

View Answer

Answer: b [Reason:] By definition.

4. Can we use linq to query against a DataTable?
a) Yes
b) No
c) Either Yes or No
d) None of the mentioned

View Answer

Answer: b [Reason:] We cannot use query against the DataTable’s Rows collection, since DataRowCollection doesn’t implement IEnumerable. We need to use the AsEnumerable() extension for DataTable. As an example: var results = from myRow in myDataTable.AsEnumerable() where myRow.Field(“RowNo”) == 1 select myRow;

5. What will be the output of given code snippet?

  1.  class Program
  2.  {
  3.      static void Main(string[] args)
  4.      {
  5.          int[] nums = { 1, -2, 3, 0, -4, 5};
  6.          var posNums = from n in nums
  7.                        where n >= 0
  8.                        select n;
  9.         foreach (int i in posNums) 
  10.         Console.Write(i + " ");
  11.         Console.WriteLine();
  12.         Console.ReadLine();
  13.     }
  14. }

a) 0, 1, -2, -4, 5
b) 1, 3, 0, 5
c) 1, 3, 5
d) Run time error

View Answer

Answer: b [Reason:] A simple linq query generated program to show a query is implemented using linq. Output : 1, 3, 0, 5

6. Select the namespace which should be included while making use of LINQ operations:
a) System.Text
b) System.Collections.Generic
c) System.Linq
d) None of the mentioned

View Answer

Answer: c [Reason:] By definition.

7. Select the output for the given code snippet:

  1.  class Program
  2.  {
  3.      static void Main(string[] args)
  4.      {
  5.          int[] nums = { 1, -2, 3, 0, -4, 5 };
  6.          var posNums = from n in nums
  7.                        where n % 2 ==0
  8.                        select n;
  9.             Console.Write("The positive values in nums: ");
  10.             foreach (int i in posNums) Console.Write(i + " ");
  11.             Console.WriteLine();
  12.             Console.ReadLine();
  13.         }
  14.     }

a) code run successfully prints nothing
b) run time error
c) code run successfully and executes output
d) compile time error

View Answer

Answer: c [Reason:] -2, 0, -4

8. Select the output for given code snippet:

  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         int[] nums = { 1, -2, 3, 0, -4, 5 };
  6.         var posNums = from n in nums
  7.                        where n > -5 && n < 6
  8.                        orderby n descending
  9.                        select n;
  10.         Console.Write("The positive values in nums: ");
  11.         foreach (int i in posNums) Console.Write(i + " ");
  12.         Console.WriteLine();
  13.         Console.ReadLine();
  14.     }
  15. }

a) Prints nothing code runs successfully
b) Run time error
c) Arranged in descending order code runs successfully
d) Compile time error

View Answer

Answer: c [Reason:] None. Output :5, 3, 1, 0, -2, -4

9. Select the output for given code snippet:

  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         int[] nums = { 16,  9, 25};
  6.         var posNums = from n in nums
  7.                       where n > 0 
  8.                       select Math.Sqrt(n);
  9.  
  10.         Console.Write("The positive values in nums: ");
  11.         foreach (int i in posNums) Console.Write(i + " ");
  12.         Console.WriteLine();
  13.         Console.ReadLine();
  14.     }
  15. }

a) Code runs successfully prints nothing
b) Code runs successfully prints required output
c) Run time error
d) Compile time error

View Answer

Answer: b [Reason:] None. Output : 4, 3, 5

10. Select the output for given code snippet:

  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         int[] nums = {1};
  6.         var posNums = from n in nums
  7.                       wheres n > 0 
  8.                      select Math.Max(78, 9);
  9.         Console.Write("The largest values in nums: ");
  10.         foreach (int i in posNums) Console.Write(i + " ");
  11.         Console.WriteLine();
  12.         Console.ReadLine();
  13.     }
  14. }

a) Code runs successfully prints nothing
b) Run time error
c) Code runs successfully prints required output
d) Compile time error

View Answer

Answer: c [Reason:] None. Output : The largest values in nums: 78

C# MCQ Set 2

1. Which namespace is mostly preferred for the operation of networking in C#?
a) System.Web
b) System.in
c) System.Net.Mail
d) All of the mentioned

View Answer

Answer: c [Reason:] Networking support is contained in several namespaces defined by the .NET Framework.The primary namespace for networking is System.Net. It defines a large number of high-level, easy-to-use classes that support various types of operations common to the Internet.Several namespaces nested under System.Net are also provided. Example :System.Net.Mail.

2. Which of the following are the classes defined by the namespace System.Net:
a) Cookie
b) CookieContainer
c) FileWebRequest
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

3. Which of the following are the interfaces defined by the namespace System.Net:
a) IAuthenticationModule
b) HttpWebRequest
c) WebProxy
d) HttpResponseHeader

View Answer

Answer: a [Reason:] c and d are namespaces and enumerations.

4. Which of the following are the classes that support the standard HTTP protocol
a) HttpWebRequest
b) HttpResponseHeader
c) HttpRequestHeader
d) HttpStatusCode

View Answer

Answer: a [Reason:] The derived classes that support the standard HTTP protocol are HttpWebRequest and HttpWebResponse.

5. Which of the following class/classes supports the task of uploading and downloading the file:
a) WebRequest
b) WebResponse
c) WebClient
d) All of the mentioned

View Answer

Answer: c [Reason:] If we only need to upload or download a file, then WebClient is often the best way to accomplish it.

6. How many ports of TCP/IP are reserved for specific protocols?
a) 10
b) 1024
c) 2048
d) 512

View Answer

Answer: b [Reason:] None.

7. How many bits are present in a single IP address?
a) 8
b) 16
c) 32
d) 64

View Answer

Answer: c [Reason:] None.

8. Which of the following is the full form of DNS?
a) Data Network Service
b) Data Name Service
c) Domain Network Service
d) Domian Name Service

View Answer

Answer: d [Reason:] None.

9. Which of the following classes is used to encapsulate IP address and DNS?
a) DatagramPacket
b) URL
c) InetAddress
d) ContentHandler

View Answer

Answer: c [Reason:] InetAddress class encapsulates both IP address and DNS. We can interact with this class by using the name of an IP host.

10. Which of the following are the protocols defined by .NET runtime:
a) HTTP
b) HTTPS
c) File
d) All of the mentioned

View Answer

Answer: d [Reason:] The .NET runtime defines HTTP, HTTPS, file, and FTP protocols. Thus, if we specify a URI that uses HTTP prefix, we will automatically receive the HTTP-compatible class that supports it. If we specify a URI that uses FTP prefix, we will automatically receive the FTP-compatible class that supports it.

C# MCQ Set 3

1. Which of the following is not a namespace in the .NET Framework Class Library?
a) System.Process
b) System.Security
c) System.Threading
d) System.xml

View Answer

Answer: a [Reason:] None.

2. Which is the correct statement about the namespaces in C#.NET?
a) Nesting of namespaces is permitted, provided all the inner namespaces are declared in the same file
b) A namespace cannot be tested
c) There is no limit on the number of levels while nesting namespaces
d) All of the mentioned

View Answer

Answer: c [Reason:] None.

3. Which among the following does not belong to the C#.NET namespace?
a) class
b) struct
c) enum
d) data

View Answer

Answer: d [Reason:] None.

4. Which among the following is a correct statement about namespace used in C#.NET?
a) Classes must belong to a namespace, whereas structures need not
b) All elements of the namespace must to belong to one file
c) If not mentioned, a namespace takes the name of the current project
d) All of the mentioned

View Answer

Answer: c [Reason:] None.

5. Which among the given is not a correct way to call the method Issue() defined in the code snippet given below?

  1. class Book
  2. {
  3.     public void issue()
  4.     {
  5.       /* code */
  6.     }
  7. }
  8. class Journel
  9. {
  10.      public void issue()
  11.      {
  12.          /* code */
  13.      }
  14. }

a) College.Lib.Book b = new College.Lib.Book();
b.issue();
b) Book b = new Book();
b.issue();
c) using College.Lib;
Book b = new Book();
b.issue();
d) All of the mentioned

View Answer

Answer: b [Reason:] None.

6. Which among the following statements are not correct about a namespace used in C#.NET?
a) Nested namespaces are allowed
b) Importing outer namespaces imports inner namespace
c) Nested namespaces are allowed
d) Importing outer namespace does not import inner namespace

View Answer

Answer: b [Reason:] None.

7. Which among the following is a .NET namespace?
a) System.Web
b) System.Process
c) System.Drawing2D
d) System.Drawing3D

View Answer

Answer: a [Reason:] None.

8. If a class named csharp is present in namespace n1 as well as in namespace n2,then which of the following is the correct way to use csharp class?

a) class Program
{
static void Main(string[] args)
{
import n1;
csharp x = new csharp();
x.fun();
import n2;
csharp y = new csharp();
y.fun();
}
}
b) import n1;
import n2;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
 
n1.csharp x = new n1.csharp();
x.fun();
import n2;
n2.csharp y = new n2.csharp();
y.fun();
}
}
}
c)   class Program
{
static void Main(string[] args)
{
using n1;
csharp x = new csharp();
x.fun();
using n2;
csharp y = new csharp();
y.fun();
}
}
d) using n1;
using n2;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
 
n1.csharp x = new n1.csharp();
x.fun();
import n2;
n2.csharp y = new n2.csharp();
y.fun();
}
}
}

View Answer

Answer: c [Reason:] None.

9. If ListBox is the class of System.Windows.Forms namespace.Then,correct way to create an object of ListBox class is?
a) using System.Windows.Forms;
ListBox I = new ListBox();
b) System.Windows.Forms.ListBox I = new System.Windows.Forms.ListBox();
c) using LBControl I = new System.Windows.Forms.ListBox;
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

10. Which among the following is the correct statement about the using statement used in C#.NET?
a) A C#.NET source code file consists of any number of using statement
b) By using ‘using’ statement it’s possible to create an alias for the namespace but not for the namespace element
c) It is permitted to define a member at namespace level using alias
d) Using statement can be placed anywhere in the C#.NET source code file

View Answer

Answer: c [Reason:] None.

C# MCQ Set 4

1. For the code set given below,which of the following statements are perfectly valid?

  1. public class MyContainer<T> where T: class, IComparable
  2. {
  3.   /* insert code here */
  4. }

a) Class MyConatiner requires that its type argument must implement Icomparable interface
b) There are multiple constraints on type argument to MyConatiner class
c) Compiler will report an error
d) None of the mentioned

View Answer

Answer: b [Reason:] None.

2. For the code given below which statements are perfectly valid?

  1. public class Csharp
  2. {
  3.     public void subject<S>(S arg)
  4.     {
  5.         Console.WriteLine(arg);
  6.     }
  7. }
  8. class Program
  9. {
  10.     static Void Main(string[] args)
  11.     {
  12.         Csharp c = new Csharp();
  13.         c.subject("hi");
  14.         c.subject(20);
  15.     }
  16. }

a) Run time exception error
b) Compile time error
c) Code runs successfully and prints required output
d) None of the mentioned

View Answer

Answer: c Output : hi 20

3. Which of given statements are valid about generics in .NET Framework?
a) generics are useful in collection classes in .NET framework
b) generics delegates are not allowed in C#.NET
c) generics is a not language feature
d) all of the mentioned

View Answer

Answer: a [Reason:] None.

4. Which statement is valid for the given snippet of code:

  1. public class Generic<T>
  2. {
  3.     public T Field;
  4. }
  5. class Program
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         Generic<String> g = new Generic<String>();
  10.         g.Field = "Hi";
  11.         Console.WriteLine(g.Field);
  12.     }
  13. }

a) Compile time error
b) Generic being a keyword cannot be used as a class name
c) Run time error
d) Code runs successfully

View Answer

Answer: d Output : Hello

5. Choose the output for given set of code:

  1.  public class Generic<T>
  2.  {
  3.      public T Field;
  4.  }
  5.  class Program
  6.  {
  7.      static void Main(string[] args)
  8.      {
  9.          Generic<int> g2 = new Generic<int>();
  10.          Generic<int> g3 = new Generic<int>();
  11.          g2.Field = 8;
  12.          g3.Field = 4;
  13.          if (g2.Field % g3.Field == 0)
  14.          {
  15.              Console.WriteLine("A");
  16.          }
  17.          else
  18.          Console.WriteLine("Prints nothing:");
  19.          Console.ReadLine();
  20.      }
  21.  }

a) Compile time error
b) A
c) Run time error
d) Code runs successfully but prints nothing

View Answer

Answer: b Output : A

6. Which of the following is a valid statement about generic procedures in C#.NET are?
a) All procedures in a Generic class are generic
b) Generic procedures should take at least one type parameter
c) Only those procedures labeled as Generic are Generic
d) None of the mentioned

View Answer

Answer: b [Reason:] None.

7. For the code set given below,which of the following statements are perfectly valid?

  1. public class MyContainer<T> where T: IComparable
  2. {
  3.   /* insert code here */
  4. }

a) Class MyConatiner requires that its type arguement must implement Icomparable interface
b) There are multiple constraints on type arguement to MyContainer class
c) Type arguement of class MyContainer should be Icomparable
d) None of the mentioned

View Answer

Answer: a [Reason:] None.

8. Choose the statements which are valid for given code snippet:

  1. public class Generic<T>
  2. {
  3.     public T Field;
  4.     public void testSub()
  5.     {
  6.         T i = Field + 1;
  7.     }
  8. }
  9. class Program
  10. {
  11.     static void Main(string[] args)
  12.     {
  13.         Generic<int>g = new Generic<int>();
  14.         g.testSub();
  15.     }
  16. }

a) code runs successfully but prints nothing
b) code runs successfully and prints 1
c) program will give run time error
d) compile time error

View Answer

Answer: d [Reason:] compiler will give error as operator ‘+’ is not defined for types ‘T’ and ‘int’

9. Which among the given classes represents System.Collections.Generic namespace?
a) SortedDictionary
b) Sorted Array
c) Stack
d) All of the mentioned

View Answer

Answer: a [Reason:] None.

10. What will be the output of given code snippet?

  1. public class Generic<T>
  2. {
  3.     Stack<T> stk = new Stack<T>();
  4.     public void push(T obj)
  5.     {
  6.         stk.Push(obj);
  7.     }
  8.     public T pop()
  9.     {
  10.         T obj = stk.Pop();
  11.         return obj;
  12.     }
  13. }
  14. class Program
  15. {
  16.     static void Main(string[] args)
  17.     {
  18.         Generic<int> g = new Generic<int>();
  19.         g.push("Csharp");
  20.         Console.WriteLine(g.pop());
  21.         Console.ReadLine();
  22.     }
  23. }

a) Compile time error
b) Csharp
c) 0
d) Run time error

View Answer

Answer: b Output : Csharp

11. What will be the output of the given code snippet?

  1. public class Generic<T>
  2. {
  3.     Stack<T> stk = new Stack<T>();
  4.     public void push(T obj)
  5.     {
  6.         stk.Push(obj);
  7.     }
  8.     public T pop()
  9.     {
  10.         T obj = stk.Pop();
  11.         return obj;
  12.     }
  13. }
  14. class Program
  15. {
  16.     static void Main(string[] args)
  17.     {
  18.         Generic<string> g = new Generic<string>();
  19.         g.push(30);
  20.         Console.WriteLine(g.pop());
  21.         Console.ReadLine();
  22.     }
  23. }

a) 0
b) 30
c) Runtime Error
d) Compile time Error

View Answer

Answer: b [Reason:] None. Output : 30.

12. What will be the output of the given code snippet?

  1. public class Generic<T>
  2. {
  3.     Stack<T> stk = new Stack<T>();
  4.     public void push(T obj)
  5.     {
  6.         stk.Push(obj);
  7.     }
  8.     public T pop()
  9.     {
  10.         T obj = stk.Pop();
  11.         return obj;
  12.     }
  13. }
  14. class Program
  15. {
  16.     static void Main(string[] args)
  17.     {
  18.         Generic<string> g = new Generic<string>();
  19.         g.push("C++");
  20.         Console.WriteLine(g.pop() + " ");
  21.         Generic<int> g1 = new Generic<int>();
  22.         g1.push(20);
  23.         Console.WriteLine(g1.pop());
  24.         Console.ReadLine();
  25.     }
  26. }

a) C++
b) 20
c) C++
20
d) 0

View Answer

Answer: c [Reason:] None. Output : C++ 20

C# MCQ Set 5

1. What is an iterator?
a) a method
b) an operator
c) accessor
d) all of the mentioned

View Answer

Answer: d [Reason:] An iterator is a method, operator, or accessor that returns the members of a set of objects, one member at a time, from start to finish.

2. What will be the output of the given code snippet?

  1.  class MyClass
  2.  {
  3.      char[] chrs = { 'A', 'B', 'C', 'D' };
  4.      public System.Collections.IEnumerator GetEnumerator()
  5.      {
  6.          foreach (char ch in chrs)
  7.          yield return ch;
  8.      }
  9.  }
  10.  class Program
  11.  {
  12.      static void Main(string[] args)
  13.      {
  14.          MyClass mc = new MyClass();
  15.          foreach (char ch in mc)
  16.          Console.Write(ch + " ");
  17.          Console.WriteLine();
  18.          Console.ReadLine();
  19.      }
  20.  }

a) Run time error
b) Compile time error
c) Code runs successfully prints nothing
d) Code runs successfully prints A, B, C, D

View Answer

Answer: d [Reason:] None. Output: A, B, C, D

3. Choose the correct statements about part of given code defined above?

  1.  public System.Collections.IEnumerator GetEnumerator()
  2.  {
  3.      foreach (char ch in chrs)
  4.      yield return ch;
  5.  }

a) Definition of iterator for MyClass
b) Implements the GetEnumerator() method defined by IEnumerable
c) The yield return statement returns the next object in the collection, which in this case is the next character in chrs
d) All of the mentioned

View Answer

Answer: d [Reason:] This is the definition of the iterator for MyClass. The code implicitly implements the GetEnumerator() method defined by IEnumerable. At the body of the method. It contains a foreach loop that returns the elements in chrs. It does this through the use of a yield return statement. The yield return statement returns the next object in the collection, which in this case is the next character in chrs.

4. What does the yield return statement specify in above code snippet?
a) returns the output
b) returns the next object in the collection
c) both a & b
d) none of the mentioned

View Answer

Answer: b [Reason:] The yield return statement returns the next object in the collection, which in this case is the next character in chrs in above code.

5. What does the given code snippet specify?

  1. class MyClass
  2. {
  3.     char chrs = 'A' ;
  4.     public IEnumerator GetEnumerator()
  5.     {
  6.         for (int i = 20; i >=0; --i)
  7.         yield return (char)((chrs + i));
  8.     }
  9. }
  10. class Program
  11. {
  12.     static void Main(string[] args)
  13.     {
  14.         MyClass mc = new MyClass();
  15.         foreach (char ch in mc)
  16.         Console.Write(ch + " ");
  17.         Console.WriteLine();
  18.         Console.ReadLine();
  19.     }
  20. }

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

View Answer

Answer: c [Reason:] None. Output: U T S R Q P O N M L K J I H G F E D C B A

6. What will the given code snippet specify?

  1. class MyClass
  2. {
  3.     char chrs = 'A' ;
  4.     public IEnumerator GetEnumerator()
  5.     {
  6.         for (int i = 20; i >=0; --i)
  7.         if (i == 10) yield break;
  8.         yield return (char)((chrs + i));
  9.     }
  10. }
  11. class Program
  12. {
  13.     static void Main(string[] args)
  14.     {
  15.         MyClass mc = new MyClass();
  16.         foreach (char ch in mc)
  17.         Console.Write(ch + " ");
  18.         Console.WriteLine();
  19.         Console.ReadLine();
  20.     }
  21. }

a) Code run successfully prints nothing
b) A B C D E F G H I J K L M N O P Q R S T U V
c) U T S R Q P O N M L
d) Compile time error

View Answer

Answer: c [Reason:] The code to specify stoppage of the iterator using ‘yield break’ statement When this statement executes, the iterator signals that the end of the collection has been reached, which effectively stops the iterator. Output: U T S R Q P O N M L

7. What will be the output of the code snippet?

  1.  class MyClass
  2.  {
  3.      int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
  4.      public IEnumerator GetEnumerator()
  5.      {
  6.          for (int i = 0; i < 20; i++)
  7.          {
  8.              if (a[i] % 2 == 0)
  9.              yield return (int)(a[i]);
  10.          }
  11.      }
  12.  }
  13.  class Program
  14.  {
  15.      static void Main(string[] args)
  16.      {
  17.          MyClass mc = new MyClass();
  18.          foreach (int i in mc)
  19.          Console.Write(i + " ");
  20.          Console.WriteLine();
  21.          Console.ReadLine();
  22.      }
  23.  }

a) prints nothing code run successfully
b) run time error
c) code runs successfully prints even number between 1 to 20
d) compile time error

View Answer

Answer: c [Reason:] None. Output: 2, 4, 6, 8, 10, 12, 14, 16, 18, 20

8. What will be the output of the code snippet?

  1.  class MyClass
  2.  {
  3.      char ch = 'A';
  4.      public IEnumerable MyItr(int end)
  5.      {
  6.          for (int i = 0 ;i < end ;i++)
  7.          yield return (char)(ch + i);
  8.      }
  9.      public IEnumerable MyItr(int begin, int end)
  10.      {
  11.          for (int i = begin ;i < end ;i++)
  12.          yield return (char)(ch + i);
  13.      }
  14.  }
  15.  class Program
  16.  {
  17.      static void Main(string[] args)
  18.      {
  19.          MyClass mc = new MyClass();
  20.          Console.WriteLine("Iterate the first 7 letters:");
  21.          foreach (char ch in mc.MyItr(7))
  22.          Console.Write(ch + " ");
  23.          Console.WriteLine("n");
  24.          Console.WriteLine("Iterate letters from F to L:");
  25.          foreach (char ch in mc.MyItr(7, 12))
  26.          Console.Write(ch + " ");
  27.          Console.WriteLine();
  28.          Console.ReadLine();
  29.      }
  30.  }

a) Iterate the first 7 letters:
A B C D E F G
Iterate letters from F to L:
G H I J K L
b) Iterate the first 7 letters:
A B C D E F G
Iterate letters from F to L:
H I J K L
c) Run time error
d) Compile time error

View Answer

Answer: b [Reason:] None. Output: Iterate the first 7 letters: A B C D E F G Iterate letters from F to L: H I J K L

9. What will be the output of the code snippet?

  1. class MyClass
  2. {
  3.     char ch = 'A';
  4.     int e = 4;
  5.     int k = 9;
  6.     int z = 6;
  7.     public IEnumerator GetEnumerator()
  8.     {
  9.         for (int i = 0; i < 26; i++)
  10.         {
  11.             if (i == e*k /z) yield break; 
  12.             yield return (int)(ch + i);
  13.         }
  14.     }
  15. }
  16. class Program
  17. {
  18.     static void Main(string[] args)
  19.     {
  20.         MyClass mc = new MyClass();
  21.         foreach(int ch in mc)
  22.         Console.Write(ch + " ");
  23.         Console.WriteLine();
  24.         Console.ReadLine();
  25.     }
  26. }

a) Compile time error
b) Run time error
c) 65 66 67 68 69 70
d) Code run successfully prints nothing

View Answer

Answer: c [Reason:] None. Output: 65 66 67 68 69 70

10. What are the advantages of the named iterator?
a) They allow to pass arguments to the iterator that control what elements are obtained
b) This form of iterators can be overloaded
c) Both a & b
d) None of the mentioned

View Answer

Answer: c [Reason:] By definition.