System.Text.StringBuilder.CopyTo C# (CSharp) Method

CopyTo() private method

private CopyTo ( int sourceIndex, char destination, int destinationIndex, int count ) : void
sourceIndex int
destination char
destinationIndex int
count int
return void
		public void CopyTo (int sourceIndex, char [] destination, int destinationIndex, int count)
		{
			if (destination == null)
				throw new ArgumentNullException ("destination");
			if ((Length - count < sourceIndex) ||
			    (destination.Length -count < destinationIndex) ||
			    (sourceIndex < 0 || destinationIndex < 0 || count < 0))
				throw new ArgumentOutOfRangeException ();

			for (int i = 0; i < count; i++)
				destination [destinationIndex+i] = _str [sourceIndex+i];
		}

Usage Example

Example #1
0
        private void OnSerialize()
        {
            if (mJsonText == null)
            {
                mJsonText = new System.Text.StringBuilder();
            }
            mJsonText.Clear();
            JsonSerializer serializer = new JsonSerializer();

            System.IO.StringWriter writer         = new System.IO.StringWriter(mJsonText);
            JsonTextWriter         jsonTextWriter = new JsonTextWriter(writer);

            serializer.Serialize(jsonTextWriter, Data);
            var charbuffer = System.Buffers.ArrayPool <Char> .Shared.Rent(mJsonText.Length);

            mJsonText.CopyTo(0, charbuffer, 0, mJsonText.Length);
            try
            {
                var bytes = System.Buffers.ArrayPool <byte> .Shared.Rent(mJsonText.Length * 6);

                var len = System.Text.Encoding.UTF8.GetBytes(charbuffer, 0, mJsonText.Length, bytes, 0);
                mJsonData = new ArraySegment <byte>(bytes, 0, len);
            }
            finally
            {
                System.Buffers.ArrayPool <char> .Shared.Return(charbuffer);
            }
        }
All Usage Examples Of System.Text.StringBuilder::CopyTo