// For basic understanding (code tested)
string str = "nitin";
int dynLength = str.Length;
int i = 0, j = 1, c = 0; ;
for (i = 0; i <= dynLength; i++)
{
for (j = 0; j < str.Length; j++)
{
if(str[0] == str[j]) // determining the occurances
{
c = c + 1;
}
}
Console.WriteLine(str[0] + " : " + c); // print the character with no. of occurances
str = str.Replace(str[0].ToString(),""); // remove character which is already counted;
dynLength = str.Length; // set dynamic length after remove counted character
c = 0;
i = 0;
}
Console.ReadLine();