title: Check for balanced parentheses in an expression C#
body: <p>Hope you are doing great. I have struggling with this code. I think this must work but i cant see the problem exacty (I am like blind ) where i have mistake.<br />
  Can you Please help with this.... Thanks in advance.
  BOTH String returns FALSE. but first must be TRUE.</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using UnityEngine;
  
  public class PatternFinder : MonoBehaviour
  {
      public void Check()
      {
          String test_good = &quot;()(){}{}{()}&quot;;//this must return TRUE
          String test_bad = &quot;((({}{}))()&quot;;//this must return FALSE
  
          Debug.Log(checkBalanced(test_good));
          Debug.Log(checkBalanced(test_bad));
      }
  
      public static bool checkBalanced(String check)
      {
          Stack&lt;char&gt; stack = new Stack&lt;char&gt;();
          for (int i = 0; i &lt; check.Length; i++)
          {
              char character = check[i];
              if (character == '[' || character == '{' || character == '(')
                  stack.Push(character);
              else if (character == ']' || character == '}' || character == ')')
              {
                  if (stack.Any())
                      return false;
                  switch (character)
                  {
                      case ']':
                          if (stack.Pop() != '[')
                              return false;
                          break;
                      case '}':
                          if (stack.Pop() != '{')
                              return false;
                          break;
                      case ')':
                          if (stack.Pop() != '(')
                              return false;
                          break;
                      default:
                          break;
                  }
              }
          }
          if (stack.Any())
              return true;
          return false;
      }
  }
  </code></pre>