using System.Collections.Generic;
public char? CheckMaxOccuranceOfChar(string givenstring)
char? maxOccuranceChar = null;
int maxOccuranceValue = 0;
if(string.IsNullOrEmpty(givenstring))
givenstring = givenstring.ToLower().Trim();
char[] arr = givenstring.ToCharArray();
Dictionary<char, int> _dictionary = new Dictionary<char, int>();
for(int i = 0; i < arr.Length; i++)
if(! _dictionary.ContainsKey(arr[i]))
_dictionary.Add(arr[i],1);
foreach (KeyValuePair<char, int> item in _dictionary)
if (item.Value > maxOccuranceValue)
maxOccuranceChar = item.Key;
maxOccuranceValue = item.Value;
public static void Main()
Program p = new Program();
var finalresult = p.CheckMaxOccuranceOfChar("Hello World");
Console.WriteLine("Max occurrence of a character in the string is : " + finalresult);