StringBuilder.CopyTo Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Túlterhelések
| Name | Description |
|---|---|
| CopyTo(Int32, Span<Char>, Int32) |
Másolja a karaktereket a példány egy adott szegmenséből egy céltartományba Char . |
| CopyTo(Int32, Char[], Int32, Int32) |
Másolja a karaktereket a példány egy adott szegmenséből egy céltömb Char adott szegmensére. |
CopyTo(Int32, Span<Char>, Int32)
- Forrás:
- StringBuilder.cs
- Forrás:
- StringBuilder.cs
- Forrás:
- StringBuilder.cs
- Forrás:
- StringBuilder.cs
- Forrás:
- StringBuilder.cs
Másolja a karaktereket a példány egy adott szegmenséből egy céltartományba Char .
public:
void CopyTo(int sourceIndex, Span<char> destination, int count);
public void CopyTo(int sourceIndex, Span<char> destination, int count);
member this.CopyTo : int * Span<char> * int -> unit
Public Sub CopyTo (sourceIndex As Integer, destination As Span(Of Char), count As Integer)
Paraméterek
- sourceIndex
- Int32
Ebben a példányban a kezdő pozíció, ahonnan a karaktereket átmásolja a program. Az index nulla alapú.
- count
- Int32
A másolandó karakterek száma.
Megjegyzések
Ez CopyTo a módszer akkor használható, ha egy objektum egymást követő szakaszait StringBuilder hatékonyan kell átmásolnia egy adott szakaszra.
A kód például feltölthet egy StringBuilder nagy számú karaktert tartalmazó objektumot, majd a CopyTo metódussal az objektum kisebb, egymást követő részeit StringBuilder egy olyan időtartamra másolhatja, ahol a darabok feldolgozásra kerülnek. Az objektum összes adatának StringBuilderStringBuilder feldolgozásakor az objektum mérete nullára van állítva, és a ciklus ismétlődik.
A következőre érvényes:
CopyTo(Int32, Char[], Int32, Int32)
- Forrás:
- StringBuilder.cs
- Forrás:
- StringBuilder.cs
- Forrás:
- StringBuilder.cs
- Forrás:
- StringBuilder.cs
- Forrás:
- StringBuilder.cs
Másolja a karaktereket a példány egy adott szegmenséből egy céltömb Char adott szegmensére.
public:
void CopyTo(int sourceIndex, cli::array <char> ^ destination, int destinationIndex, int count);
public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count);
[System.Runtime.InteropServices.ComVisible(false)]
public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count);
member this.CopyTo : int * char[] * int * int -> unit
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.CopyTo : int * char[] * int * int -> unit
Public Sub CopyTo (sourceIndex As Integer, destination As Char(), destinationIndex As Integer, count As Integer)
Paraméterek
- sourceIndex
- Int32
Ebben a példányban a kezdő pozíció, ahonnan a karaktereket átmásolja a program. Az index nulla alapú.
- destination
- Char[]
Az a tömb, amelyben a karaktereket kimásolja a program.
- destinationIndex
- Int32
A kezdő pozíció, ahol a destination karaktereket kimásolja a program. Az index nulla alapú.
- count
- Int32
A másolandó karakterek száma.
- Attribútumok
Kivételek
destination az null.
sourceIndex, destinationIndexvagy count, kisebb, mint nulla.
-vagy-
sourceIndex nagyobb, mint a példány hossza.
sourceIndex
+
count nagyobb, mint a példány hossza.
-vagy-
destinationIndex
+
count nagyobb, mint a hossza destination.
Példák
Az alábbi példa a metódust CopyTo mutatja be.
// This example demonstrates the CopyTo(Int32, Char[], Int32, Int32) method.
// Typically the destination array is small, preallocated, and global while
// the StringBuilder is large with programmatically defined data.
// However, for this example both the array and StringBuilder are small
// and the StringBuilder has predefined data.
using System;
using System.Text;
class Sample
{
protected static char[] dest = new char[6];
public static void Main()
{
StringBuilder src = new StringBuilder("abcdefghijklmnopqrstuvwxyz!");
dest[1] = ')';
dest[2] = ' ';
// Copy the source to the destination in 9 pieces, 3 characters per piece.
Console.WriteLine("\nPiece) Data:");
for(int ix = 0; ix < 9; ix++)
{
dest[0] = ix.ToString()[0];
src.CopyTo(ix * 3, dest, 3, 3);
Console.Write(" ");
Console.WriteLine(dest);
}
}
}
/*
This example produces the following results:
Piece) Data:
0) abc
1) def
2) ghi
3) jkl
4) mno
5) pqr
6) stu
7) vwx
8) yz!
*/
// This example demonstrates the CopyTo(Int32, Char[], Int32, Int32) method.
// Typically the destination array is small, preallocated, and global while
// the StringBuilder is large with programmatically defined data.
// However, for this example both the array and StringBuilder are small
// and the StringBuilder has predefined data.
open System.Text
let dest = Array.zeroCreate 6
let src = StringBuilder "abcdefghijklmnopqrstuvwxyz!"
dest[1] <- ')'
dest[2] <- ' '
// Copy the source to the destination in 9 pieces, 3 characters per piece.
printfn "\Piece) Data:"
for i = 0 to 8 do
dest[0] <- (string i)[0]
src.CopyTo(i * 3, dest, 3, 3)
printfn $" {dest}"
// This example produces the following results:
// Piece) Data:
// 0) abc
// 1) def
// 2) ghi
// 3) jkl
// 4) mno
// 5) pqr
// 6) stu
// 7) vwx
// 8) yz!
' Typically the destination array is small, preallocated, and global while
' the StringBuilder is large with programmatically defined data.
' However, for this example both the array and StringBuilder are small
' and the StringBuilder has predefined data.
Imports System.Text
Class Sample
Protected Shared dest(5) As Char
Public Shared Sub Main()
Dim src As New StringBuilder("abcdefghijklmnopqrstuvwxyz!")
dest(1) = ")"c
dest(2) = " "c
' Copy the source to the destination in 9 pieces, 3 characters per piece.
Console.WriteLine(vbCrLf & "Piece) Data:")
Dim ix As Integer
For ix = 0 To 8
dest(0) = ix.ToString()(0)
src.CopyTo(ix * 3, dest, 3, 3)
Console.Write(" ")
Console.WriteLine(dest)
Next ix
End Sub
End Class
'
' This example produces the following results:
'
' Piece) Data:
' 0) abc
' 1) def
' 2) ghi
' 3) jkl
' 4) mno
' 5) pqr
' 6) stu
' 7) vwx
' 8) yz!
Megjegyzések
Ez CopyTo a módszer akkor használható, ha egy objektum egymást követő szakaszait StringBuilder hatékonyan át kell másolnia egy tömbbe. A tömbnek rögzített méretűnek, előre áthelyezettnek, újrafelhasználhatónak és esetleg globálisan elérhetőnek kell lennie.
A kód például feltölthet egy StringBuilder nagy számú karaktert tartalmazó objektumot, majd a CopyTo metódussal az objektum kis, egymást követő részeit StringBuilder másolhatja egy tömbbe, ahol a darabokat feldolgozzák. Az objektum összes adatának StringBuilderStringBuilder feldolgozásakor az objektum mérete nullára van állítva, és a ciklus ismétlődik.