String inputstring = "anand swaroop";
int countValue = 1;
Dictionary<string, int> objdict = new Dictionary<string, int>();
foreach (var value in inputstring.ToCharArray())
{
if (objdict.ContainsKey(value.ToString()))
{
objdict.TryGetValue(value.ToString(), out countValue);
objdict[value.ToString()] = countValue+1;
}
else
{
objdict.Add(value.ToString(), countValue);
}
}
No comments:
Post a Comment