public string LongestPalindrome(string s) { IndexRange current = new IndexRange(0, 0); char[] charArray = s.ToCharArray(); for (int i = 0; i < charArray.Length; i++) { IndexRange range1 = Expand(charArray, i, i); if (range1 != null && range1.Length > current.Length) { current = range1; } IndexRange range2 = Expand(charArray, i, i + 1); if (range2 != null && range2.Length > current.Length) { current = range2; } } return(current.GetSubString(s)); }