C
C#15mo ago
MRW419

❔ Can anyone help explain what it's talking about?

Is it trying to get me to copy the array value from arrayOne to arrayTwo? If so, how? It never taught me that, only how arrays work.
22 Replies
SinFluxx
SinFluxx15mo ago
Arrays - C#
Store multiple variables of the same type in an array data structure in C#. Declare an array by specifying a type or specify Object to store any type.
Anu6is
Anu6is15mo ago
- what is this "it" that never taught you - yes, you are suppose to copy the elements of arrayOne into arrayTwo by iterating over arrayOne - arrayTwo should not have been declared with values defined, just a size matching arrayOne - if you know how arrays works then you can do the requested task. * read the value of arrayOne index 0 and write it to arrayTwo index 0 and so forth for each index
MRW419
MRW419OP15mo ago
I understand the basic of what it is but I guess not to this point unless we were to assigned arrayTwo to equal arrayOne like this string[] arrayOne = arrayOne Would like to read it but if I tried.... I'm not learning anything
SinFluxx
SinFluxx15mo ago
How does reading something = not learning?
MRW419
MRW419OP15mo ago
Cause it just doesn't make sense if I read it Someone explaing it through video is easier for me to learn
Angius
Angius15mo ago
Protip: you can set the value of an array at a given index using theArray[index] = newValue That and a loop should be all you need
MRW419
MRW419OP15mo ago
Thank you, I'll mess around and see what I can do Quick question do we use the arrayTwo?
Angius
Angius15mo ago
Well, yes That's the task, isn't it? To copy values from one array to the other
MRW419
MRW419OP15mo ago
Got it, just maklng sure oh, well I mean for the theArray[index]
Angius
Angius15mo ago
That's also the way to access a value at a given index, yes
MODiX
MODiX15mo ago
Angius
REPL Result: Success
void Print<T>(T[] arr) => Console.WriteLine(string.Join(", ", arr));

var arr = new[]{ 1, 2, 3 };
Print(arr);
arr[1] = 69;
Print(arr);
Console.WriteLine(arr[0]);
void Print<T>(T[] arr) => Console.WriteLine(string.Join(", ", arr));

var arr = new[]{ 1, 2, 3 };
Print(arr);
arr[1] = 69;
Print(arr);
Console.WriteLine(arr[0]);
Console Output
1, 2, 3
1, 69, 3
1
1, 2, 3
1, 69, 3
1
Compile: 701.185ms | Execution: 113.469ms | React with ❌ to remove this embed.
MRW419
MRW419OP15mo ago
You only change one number. I have to copy all of the vaule from arrayOne to arrayTwo
SinFluxx
SinFluxx15mo ago
That's where the loop comes in
MRW419
MRW419OP15mo ago
Oh, so do
var arr = new[]{1, 2, 3 };
print(arr);
for (int i = 0; i < arr.Length; i++
{
arr[i] = 69;
}
var arr = new[]{1, 2, 3 };
print(arr);
for (int i = 0; i < arr.Length; i++
{
arr[i] = 69;
}
Wait is arr arrayTwo? if so then where is the value of arrayOne?
int[] arrOne = {1, 5, 6};
var arrTwo = new[]{1, 2, 3 };
print(arrTwo);
for (int i = 0; i < arrTwo.Length; i++)
{
arrTwo[i] = arrOne;
}
int[] arrOne = {1, 5, 6};
var arrTwo = new[]{1, 2, 3 };
print(arrTwo);
for (int i = 0; i < arrTwo.Length; i++)
{
arrTwo[i] = arrOne;
}
Angius
Angius15mo ago
Get the specific item from arrayone Insert 0th item from arrayOne into 0th spot in arrayTwo, 1st into 1st, and so on
MRW419
MRW419OP15mo ago
Could you show me?
Kouhai
Kouhai15mo ago
How do you iterate over an array using a for loop?
Angius
Angius15mo ago
Here, I highlighted the relevant parts
MRW419
MRW419OP15mo ago
Hm? What about those? Shoulden't it be covered in the for loop?
Angius
Angius15mo ago
The first highlight shows you how to set an item in the array at index 1 The second shows you how to get an item from the array at index 0 You want to insert an item from the first array's index n to the second array's index n Where n is, well, each index That's where the loop comes in
MRW419
MRW419OP15mo ago
((Sorry got out of school but i'm back)) I think I got it....
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server