Try below code:
string inputStr = "success is my life";
string[] arrayList = inputStr.Split(' ');
string pair = "";
Dictionary<string,string> tempList = new Dictionary<string,string>();
foreach (string word in arrayList)
{
pair = " ";
for (int i = 0; i <= word.Length - 1; i++)
{
if (i == word.Length - 1)
{
if (i != 0)
{
if (word[i] == word[i - 1])
{
pair += word[i];
if (tempList.ContainsKey(word.Trim()))
{
tempList[word.Trim()] = tempList[word.Trim()] + "," + pair;
}
else
{
tempList.Add(word.Trim(), pair.Trim());
}
pair = null;
}
}
}
else
{
if (i + 1 <= word.Length - 1)
{
if (word[i] == word[i + 1])
{
pair += word[i];
}
else
{
if (i != 0)
{
if (word[i] == word[i - 1])
{
pair += word[i];
if (tempList.ContainsKey(word.Trim()))
{
tempList[word.Trim()] = tempList[word.Trim()] + "," + pair;
}
else
{
tempList.Add(word.Trim(), pair.Trim());
}
pair = null;
}
}
}
}
}
}
}
foreach (var temp in tempList)
{
Console.Write(temp.Value + " - " + temp.Key + "\n");
}
Note: I just modified partially your code and implemented logic as per your need.