String.CopyTo Yöntem
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
CopyTo(Span<Char>) |
Bu dizenin içeriğini hedef yayılma alanına kopyalar. |
CopyTo(Int32, Char[], Int32, Int32) |
Belirtilen sayıda karakteri bu örnekte belirtilen konumdan Unicode karakter dizisindeki belirtilen konuma kopyalar. |
- Kaynak:
- String.cs
- Kaynak:
- String.cs
- Kaynak:
- String.cs
Bu dizenin içeriğini hedef yayılma alanına kopyalar.
public:
void CopyTo(Span<char> destination);
public void CopyTo(Span<char> destination);
member this.CopyTo : Span<char> -> unit
Public Sub CopyTo (destination As Span(Of Char))
Parametreler
Özel durumlar
Hedef yayılma alanı kaynak dizeden daha kısadır.
Şunlara uygulanır
.NET 10 ve diğer sürümler
Ürün | Sürümler |
---|---|
.NET | 6, 7, 8, 9, 10 |
- Kaynak:
- String.cs
- Kaynak:
- String.cs
- Kaynak:
- String.cs
Belirtilen sayıda karakteri bu örnekte belirtilen konumdan Unicode karakter dizisindeki belirtilen konuma kopyalar.
public:
void CopyTo(int sourceIndex, cli::array <char> ^ destination, int destinationIndex, int count);
public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count);
member this.CopyTo : int * char[] * int * int -> unit
Public Sub CopyTo (sourceIndex As Integer, destination As Char(), destinationIndex As Integer, count As Integer)
Parametreler
- sourceIndex
- Int32
Bu örnekte kopyalanacak ilk karakterin dizini.
- destination
- Char[]
Bu örnekteki karakterlerin kopyalandığı Unicode karakter dizisi.
- destinationIndex
- Int32
Kopyalama işleminin başladığı dizin destination
.
- count
- Int32
Bu örnekte kopyalanacak destination
karakter sayısı.
Özel durumlar
destination
, null
değeridir.
sourceIndex
, destinationIndex
veya count
negatiftir
-veya-
sourceIndex
geçerli örnekteki bir konumu tanımlamaz.
-veya-
destinationIndex
dizideki destination
geçerli bir dizini tanımlamaz.
-veya-
count
bu örneğin sonuna kadar olan alt dizenin sourceIndex
uzunluğundan büyük
-veya-
count
, dizinin sonuna kadar olan alt dizi destinationIndex
uzunluğundan destination
büyüktür.
Örnekler
Aşağıdaki örnekte yöntemi gösterilmektedir CopyTo .
using namespace System;
int main()
{
// Embed an array of characters in a string
String^ strSource = "changed";
array<Char>^destination = {'T','h','e',' ','i','n','i','t','i','a','l',' ','a','r','r','a','y'};
// Print the char array
Console::WriteLine( destination );
// Embed the source string in the destination string
strSource->CopyTo( 0, destination, 4, strSource->Length );
// Print the resulting array
Console::WriteLine( destination );
strSource = "A different string";
// Embed only a section of the source string in the destination
strSource->CopyTo( 2, destination, 3, 9 );
// Print the resulting array
Console::WriteLine( destination );
}
// The example displays the following output:
// The initial array
// The changed array
// Thedifferentarray
using System;
public class CopyToTest {
public static void Main() {
// Embed an array of characters in a string
string strSource = "changed";
char [] destination = { 'T', 'h', 'e', ' ', 'i', 'n', 'i', 't', 'i', 'a', 'l', ' ',
'a', 'r', 'r', 'a', 'y' };
// Print the char array
Console.WriteLine( destination );
// Embed the source string in the destination string
strSource.CopyTo ( 0, destination, 4, strSource.Length );
// Print the resulting array
Console.WriteLine( destination );
strSource = "A different string";
// Embed only a section of the source string in the destination
strSource.CopyTo ( 2, destination, 3, 9 );
// Print the resulting array
Console.WriteLine( destination );
}
}
// The example displays the following output:
// The initial array
// The changed array
// Thedifferentarray
// Embed an array of characters in a string
let strSource = "changed"
let destination =
[| 'T'; 'h'; 'e'; ' '; 'i'; 'n'; 'i'; 't'; 'i'; 'a'; 'l'; ' ';
'a'; 'r'; 'r'; 'a'; 'y' |]
// Print the char array
printfn $"{destination}"
// Embed the source string in the destination string
strSource.CopyTo( 0, destination, 4, strSource.Length)
// Print the resulting array
printfn $"{destination}"
let strSource2 = "A different string"
// Embed only a section of the source string in the destination
strSource2.CopyTo( 2, destination, 3, 9)
// Print the resulting array
printfn $"{destination}"
// The example displays the following output:
// The initial array
// The changed array
// Thedifferentarray
Public Class CopyToTest
Public Shared Sub Main()
' Embed an array of characters in a string
Dim strSource As String = "changed"
Dim destination As Char() = {"T"c, "h"c, "e"c, " "c, "i"c, "n"c, "i"c, _
"t"c, "i"c, "a"c, "l"c, " "c, "a"c, "r"c, "r"c, "a"c, "y"c}
' Print the char array
Console.WriteLine(destination)
' Embed the source string in the destination string
strSource.CopyTo(0, destination, 4, strSource.Length)
' Print the resulting array
Console.WriteLine(destination)
strSource = "A different string"
' Embed only a section of the source string in the destination
strSource.CopyTo(2, destination, 3, 9)
' Print the resulting array
Console.WriteLine(destination)
End Sub
End Class
' The example displays the following output:
' The initial array
' The changed array
' Thedifferentarray
Açıklamalar
Bu yöntem, bu örneğin konumundaki sourceIndex
karakterleri karakter dizisinin konumuna destinationIndex
destination
kopyalarcount
. Bu yöntem karakter dizisini destination
yeniden boyutlandırmaz; kopyalanan karakterleri barındırmak için yeterli sayıda öğeye sahip olması gerekir veya yöntem bir ArgumentOutOfRangeExceptionoluşturur.
sourceIndex
ve destinationIndex
sıfır tabanlıdır.
Ayrıca bkz.
Şunlara uygulanır
.NET 10 ve diğer sürümler
Ürün | Sürümler |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET geri bildirimi
.NET, açık kaynak bir projedir. Geri bildirim sağlamak için bir bağlantı seçin: