我有一个字符串元素数组,我希望将这些值复制到一个新的数组中。我可以怎么做?
1条回答 默认 最新
- dpkrh2444 2015-06-07 17:40关注
You can declare a new array of the same type and copy over the values by assigning it.
// Declare a string array of five elements. var array1 [5]string // Declare a second string array of five elements. // Initialise the array with values. array2 := [5]string{"A", "B", "C", "D", "E"} // Copy the values from array2 into array1. array1 = array2
Keep in mind that you cannot assign over an array of different size:
// Declare a string array of four elements. var array1 [4]string // Declare a second string array of five elements. // Initialize the array with colors. array2 := [5]string{"A", "B", "C", "D", "E"} // Copy the values from array2 into array1. array1 = array2 Compiler Error: cannot use array2 (type [5]string) as type [4]string in assignment
解决评论 打赏 举报无用 1
悬赏问题
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog
- ¥15 Excel发现不可读取的内容
- ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
- ¥20 yolov5自定义Prune报错,如何解决?