日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

c#copyto_String.CopyTo()方法以及C#中的示例

發布時間:2025/3/11 C# 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c#copyto_String.CopyTo()方法以及C#中的示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

c#copyto

C#String.CopyTo()方法 (C# String.CopyTo() Method)

String.CopyTo() method is used to copy a specified number of characters from given indexes of the string to the specified position in a character array.

String.CopyTo()方法用于將指定數量的字符從給定的字符串索引復制到字符數組中的指定位置。

Syntax:

句法:

public void CopyTo (int source_index, char[] destination, int destination_index, int count);

Parameter:

參數:

  • source_index - index to the string from where you want to copy the string

    source_index-要從中復制字符串的字符串的索引

  • destination - target character array in which you want to copy the part of the string

    destination-您要在其中復制字符串部分的目標字符數組

  • destination_index - index in the targeted character array

    destination_index-目標字符數組中的索引

  • count - total number of characters to be copied in character array

    count-要在字符數組中復制的字符總數

Return value: void - It returns nothing.

返回值: void-不返回任何內容。

Example:

例:

Input:string str = "Hello world!";char[] arr = { 'I', 'n', 'c', 'l', 'u', 'd', 'H', 'e', 'l', 'p' };copying "Hello " to arr:str.CopyTo(0, arr, 0, 6);Output:str = Hello world!arr = Hello Help

C#使用String.CopyTo()方法將字符從字符串復制到字符數組的示例 (C# Example to copy a characters from string to characters array using String.CopyTo() method)

using System; using System.Text;namespace Test {class Program{static void printCharArray(char[] a){foreach (char item in a){Console.Write(item);}}static void Main(string[] args){string str = "Hello world!";char[] arr = { 'I', 'n', 'c', 'l', 'u', 'd', 'H', 'e', 'l', 'p' };//printing valuesConsole.WriteLine("Before CopyTo...");Console.WriteLine("str = " + str);Console.Write("arr = ");printCharArray(arr);Console.WriteLine();//copying "Hello " to arrstr.CopyTo(0, arr, 0, 6);//printing valuesConsole.WriteLine("After CopyTo 1)...");Console.WriteLine("str = " + str);Console.Write("arr = ");printCharArray(arr);Console.WriteLine();//copying "World! " to arrstr.CopyTo(6, arr, 0, 6);//printing valuesConsole.WriteLine("After CopyTo 1)...");Console.WriteLine("str = " + str);Console.Write("arr = ");printCharArray(arr);Console.WriteLine();//hit ENTER to exitConsole.ReadLine();}} }

Output

輸出量

Before CopyTo... str = Hello world! arr = IncludHelp After CopyTo 1)... str = Hello world! arr = Hello Help After CopyTo 1)... str = Hello world! arr = world!Help

Reference: String.CopyTo(Int32, Char[], Int32, Int32) Method

參考: String.CopyTo(Int32,Char [],Int32,Int32)方法

翻譯自: https://www.includehelp.com/dot-net/string-copyto-method-with-example-in-c-sharp.aspx

c#copyto

總結

以上是生活随笔為你收集整理的c#copyto_String.CopyTo()方法以及C#中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。