本文整理汇总了C#中String.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# String.CopyTo方法的具体用法?C# String.CopyTo怎么用?C# String.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.CopyTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TypeLexer
public TypeLexer(String s)
{
// Turn the string into a char array with a NUL terminator.
char[] chars = new char[s.Length + 1];
s.CopyTo(0, chars, 0, s.Length);
_chars = chars;
_index = 0;
}
示例2: AssemblyNameLexer
internal AssemblyNameLexer(String s)
{
// Convert string to char[] with NUL terminator. (An actual NUL terminator in the input string will be treated
// as an actual end of string: this is compatible with desktop behavior.)
char[] chars = new char[s.Length + 1];
s.CopyTo(0, chars, 0, s.Length);
_chars = chars;
_index = 0;
}
示例3: WriteAsyncInternal
// We pass in private instance fields of this MarshalByRefObject-derived type as local params
// to ensure performant access inside the state machine that corresponds this async method.
// Fields that are written to must be assigned at the end of the method *and* before instance invocations.
private static async Task WriteAsyncInternal(StreamWriter _this, String value,
Char[] charBuffer, Int32 charPos, Int32 charLen, Char[] coreNewLine,
bool autoFlush, bool appendNewLine)
{
Contract.Requires(value != null);
int count = value.Length;
int index = 0;
while (count > 0)
{
if (charPos == charLen) {
await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
Debug.Assert(_this.charPos == 0);
charPos = 0;
}
int n = charLen - charPos;
if (n > count)
n = count;
Debug.Assert(n > 0, "StreamWriter::Write(String) isn't making progress! This is most likely a race condition in user code.");
value.CopyTo(index, charBuffer, charPos, n);
charPos += n;
index += n;
count -= n;
}
if (appendNewLine)
{
for (Int32 i = 0; i < coreNewLine.Length; i++) // Expect 2 iterations, no point calling BlockCopy
{
if (charPos == charLen) {
await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
Debug.Assert(_this.charPos == 0);
charPos = 0;
}
charBuffer[charPos] = coreNewLine[i];
charPos++;
}
}
if (autoFlush) {
await _this.FlushAsyncInternal(true, false, charBuffer, charPos).ConfigureAwait(false);
Debug.Assert(_this.charPos == 0);
charPos = 0;
}
_this.CharPos_Prop = charPos;
}
示例4: Write
public override void Write(String value)
{
if (value != null)
{
CheckAsyncTaskInProgress();
int count = value.Length;
int index = 0;
while (count > 0) {
if (charPos == charLen) Flush(false, false);
int n = charLen - charPos;
if (n > count) n = count;
Debug.Assert(n > 0, "StreamWriter::Write(String) isn't making progress! This is most likely a race condition in user code.");
value.CopyTo(index, charBuffer, charPos, n);
charPos += n;
index += n;
count -= n;
}
if (autoFlush) Flush(true, false);
}
}
示例5: Append
internal void Append(String s) {
int l = s.Length;
int newFreePos = _freePos + l;
if (newFreePos > _size)
Grow(newFreePos);
s.CopyTo(0, _charBuffer, _freePos, l);
_freePos = newFreePos;
}
示例6: Write
public override void Write(String s) {
int len = s.Length;
int newFreePos = _freePos + len;
if (newFreePos > _size)
Grow(newFreePos);
s.CopyTo(0, _charBuffer, _freePos, len);
_freePos = newFreePos;
}