//串赋值为串 public void ValueTo(StringList s) { if (s.isEmpty()) { Console.WriteLine("赋值的字符串不能为空!"); return; } int length = s.Length(); this._data = new char[length]; char c = default(char); for (int i = 0; i < length; i++) { s.GetCharByIndex(i + 1, ref c); this._data[i] = c; } }
//比较两个串 1本串大 -1 s串大 0相等 public int Compare(StringList s) { int sounceLength = this.Length(); int length = s.Length(); int i = 0; int j = 0; char c = '\0'; while (i < sounceLength && j < length) { s.GetCharByIndex(j + 1, ref c); if (this._data[i] > c) { return(1); } if (this._data[i] < c) { return(-1); } i++; j++; } if (sounceLength == length) { return(0); } if (sounceLength > length) { return(1); } return(-1); }