title: C# find the count of duplicate characters in an array and list them
body: <p>I am trying to find the number of duplicate characters in an array and list them. For example, the user enters "this is my house", the output should look like this:</p>
  
  <p>Number of duplicate characters is: 3 and the duplicates are: h i s</p>
  
  <p>I have to use ToCharArray()</p>
  
  <p>I've been trying but I can't get it to work properly, can you please help?</p>
  
  <p>Thanks</p>
  
  <p>Here is my code:</p>
  
  <hr>
  
  <pre><code>using System;
  class Program
  {
      static void Main()
      {
          Console.Write("type a sentence: ");
          String str = Console.ReadLine();
          char[] arr = str.ToCharArray();
  
          for (int j = 0; j &lt; arr.Length; j++)
          {
              for (int k = j + 1; k &lt; arr.Length; k++)
              {
                  if (arr[j] == arr[k] &amp;&amp; j != k)
                  {
                      Console.WriteLine("number of duplicates: " + k + "\n" + "duplicates are: " + arr[j]);
                      Console.ReadLine();
                  }
              }
          }
      }
  }
  </code></pre>
  
  <hr>