using System.Collections.Generic;
public static string inputbraces = "{}[]()";
public static void Main()
bool isformatted = checkIfWellFormatted("( 2 + [3) - 1]");
Console.WriteLine("Input value formatted:" +isformatted);
private static bool checkIfWellFormatted(string inputString)
if (string.IsNullOrEmpty(inputString))
throw new ArgumentException("String is empty");
Dictionary<char, int> _inputDictionary = new Dictionary<char, int>();
foreach (char c in inputbraces)
_inputDictionary.Add(c, 0);
foreach (char c in inputString)
if (_inputDictionary.ContainsKey(c)) _inputDictionary[c] += 1;
return _inputDictionary['{'] == _inputDictionary['}']
&& _inputDictionary['('] == _inputDictionary[')']
&& _inputDictionary['['] == _inputDictionary[']'];