-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrays-CopyTo Method.cs
More file actions
48 lines (39 loc) · 1.3 KB
/
Arrays-CopyTo Method.cs
File metadata and controls
48 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
// Author: Jonathan Scholl
// Date: 10/20/2021
// Project: Array Method - CopyTo
// Description: Need more understanding of builtin methods, so practicing them
*/
using System;
namespace Arrays_Practice___CopyTo_Method
{
class Program
{
static void Main(string[] args)
{
//create new array and print it's contents
int[] userArray = initializeArray();
Console.WriteLine($"\nOriginal Array: {printArray(userArray)}");
int[] targetArray = new int[userArray.Length + 3];
userArray.CopyTo(targetArray, 3);
Console.WriteLine($"\nNew Array: {printArray(targetArray)}");
}
//create a unique array based on how many elements
public static int[] initializeArray()
{
Console.Write("How many elements: ");
var length = int.Parse(Console.ReadLine());
int[] numArray = new int[length];
for (int x = 0; x < numArray.Length; x++)
{
numArray[x] = int.Parse(Console.ReadLine());
}
return numArray;
}
//print the contents of an array
public static string printArray(int[] numArray)
{
return "{ " + String.Join(", ", numArray) + " }";
}
}
}