/// <summary> /// Truncate the string blob to the specified last index. /// </summary> /// <param name="lastIndex">Index of last string to retain.</param> public void Truncate(int lastIndex) { if (_index is null) { Refresh(); } var l = _index[lastIndex] + get_LengthAt(lastIndex) * 2; if (_lpwstr) { l = l + 2; } else { l = l + SizeDescriptorLength; } Array.Resize(ref _index, lastIndex + 1); SafePtr.Length = l.ToInt64() - SafePtr.handle.ToInt64(); _count = _index.Length; if (!_lpwstr) { switch (SizeDescriptorLength) { case 2: { _mem.set_UShortAt(0L, (ushort)_count); break; } case 4: { _mem.set_UIntegerAt(0L, (uint)_count); break; } case 8: { _mem.set_ULongAt(0L, (ulong)_count); break; } } } }