Basic C# Code to Find Out the Occurrence of Each Character in a String

Recently I went to an interview where the interviewer asked me to write some basic code to find out the occurrence of each character in a string.
I managed to do that using some loop,¬†but it was not an optimal solution. The complexity, O(n), for that code was fairly high. I’ve continued to play with the code since, and have found a lot of options to solve this problem.