title: How to fix "The body of 'display(List<string>)' cannot be an iterator block because 'string' is not an iterator interface type"?
body: <p>I'm new to Programming. I would like to implement a program with a <code>yield</code> keyword. So That, I have created a <code>new List</code> and ask the user to enter the list values through the console.</p>
  <p>After that, I have implemented the <code>foreach</code> to that list. And Checked the condition, &quot;specific expected string&quot; is present in the list or not with the yield keyword.</p>
  <p><strong>My Expectation:</strong></p>
  <ol>
  <li>Loop through the existing list.</li>
  <li>Check that &quot;TamilSelvi&quot; is present inside the List with the help of &quot;yield&quot; keyword.</li>
  <li>Finally, return the matched string</li>
  </ol>
  <p><strong>My Implementation:</strong></p>
  <ol>
  <li><p>I have created a list.</p>
  </li>
  <li><p>set the Capacity of that list into 6.</p>
  </li>
  <li><p>Get the input for the user through the console.</p>
  </li>
  <li><p>Finally, Check that the user entered lists values having the &quot;TamilSelvi&quot; or not with the help of yield.</p>
  <pre><code> using System;
   using System.Collections.Generic;
   using System.Collections;
  
   namespace yield_Keyword_in_C_Sharp
   {
   class Program
   {
   static void Main(string[] args)
    {
       Console.WriteLine(&quot;Implementation of Yield Keyword in C# with 
    List&quot;);
       Console.WriteLine();
  
  
       // Create a List
       List&lt;string&gt; names = new List&lt;string&gt;();
       names.Capacity = 6;
  
       Console.WriteLine(&quot;Get the Input From the User&quot;);
       Console.WriteLine();
  
       //Get the List Input From the User
       foreach (string n in names)
       {
           string temp = Console.ReadLine();
           if (temp.Length != 0 &amp;&amp; temp != &quot; &quot; &amp;&amp; temp != &quot;  &quot;)
           {
               names.Add(temp);
               temp = string.Empty;
           }
       }
  
       //Print the List values entered by the user in the Console Window
       Console.WriteLine(&quot;Print the Values Entered by the User&quot;);
       Console.WriteLine();
  
       foreach (string na in names)
       {
           Console.WriteLine(na);
       }
       Console.WriteLine();
  
       Console.WriteLine(&quot;Get the TamilSelvi in above list with the help 
      of yield keyword&quot;);
       display(names);
       void display(List&lt;string&gt; words) // display method implementation
       {
           foreach (string word in words)
           {
               if (word == &quot;TamilSelvi&quot;) yield return word;
           }
       }
  
  
       Console.WriteLine();
  
       Console.ReadLine();
  
   }
   }
   }
  </code></pre>
  </li>
  </ol>
  <p><strong>Expected Result:</strong></p>
  <p>Implementation of Yield Keyword in C# with List</p>
  <p>Get the Input From the User</p>
  <p>Thirunavukkarasu</p>
  <p>TamilSelvi</p>
  <p>Vennilla</p>
  <p>Sabarinathan</p>
  <p>Muthuprakash</p>
  <p>Mutharasan</p>
  <p>Print the Values Entered by the User</p>
  <p>Thirunavukkarasu</p>
  <p>TamilSelvi</p>
  <p>Vennilla</p>
  <p>Sabarinathan</p>
  <p>Muthuprakash</p>
  <p>Mutharasan</p>
  <p>Get the TamilSelvi in above list with the help of yield keyword</p>
  <p>TamilSelvi</p>
  <p><strong>Actual Result:</strong>
  The Application couldn't build. Facing the following Error.</p>
  <p><strong>Error:</strong></p>
  <p>The body of 'display(List words)' cannot be iterator block because 'void' is not an iterator interface type.</p>