////// 判断括号是否匹配,只支持{} [] () /// /// ///private Boolean IsCorrectMatch(string strMatch) { LinkStack ls = new LinkStack(); //括号匹配组 string left = "{[(", right = "}])"; foreach(var word in strMatch) { if (left.IndexOf(word) != -1) { //是左括号 ls.Push(word); } else if (right.IndexOf(word) != -1) { //是右括号 //取出栈顶 object obj=ls.Pop(); if(obj == null) { //右括号数量 大于 左括号数量 return false; } char match = (char)obj; if (left.IndexOf(match) != right.IndexOf(word)) { //不匹配 return false; } } } if (ls.Empty() == false) { //左括号数量 大于 右括号数量 return false; } return true; }