public static bool CheckParenthesis(String str)
{
bool result = true;
if(str != null)
{
int open = 0;
int closed = 0;
int i = 0;
while((i = str.IndexOf('(', i)) >= 0)
{
i++;
open++;
}
i = 0;
while((i = str.IndexOf(')', i)) >= 0)
{
i++;
closed++;
}
result = (open == closed);
}
return result;
}