arry with loops

how to Check if the array is equal. Two arrays are equal if their sizes are same, and elements with same index from both arrays are same.  Display both arrays.  Display if the array is equal or not equal. no one was able to answer this question any help (edited)
46 Replies
hercules_x_x
hercules_x_xOP3y ago
yes its in my uni and need to do it with loop no one was able to answe it the teacher said set your own arry value array*
hercules_x_x
hercules_x_xOP3y ago
this is the full q
hercules_x_x
hercules_x_xOP3y ago
from the array it self like the length count so array from 0 but the value in it start from 1
mtreit
mtreit3y ago
Do you know how to get the length?
hercules_x_x
hercules_x_xOP3y ago
int[,] arr = ( (1, 2, 3), (4, 5, 6 ), ( 7, 8, 9} }; for example this got 2 array Right ? 0 1 2 yes i know
MODiX
MODiX3y ago
Diddy#2634
REPL Result: Success
int[] arr1 = new int[] { 1, 2, 3};
Console.WriteLine(arr1.Length);
int[] arr1 = new int[] { 1, 2, 3};
Console.WriteLine(arr1.Length);
Console Output
3
3
Compile: 587.518ms | Execution: 64.545ms | React with ❌ to remove this embed.
hercules_x_x
hercules_x_xOP3y ago
this one i dont know i don’t know how to compare vvalues
mtreit
mtreit3y ago
Are you actually trying to do this for multi-dimensional arrays?
hercules_x_x
hercules_x_xOP3y ago
Maybe i can declare tow array then loop them? if(int x= 5; ) wait wait let me try shit i give up oh yaaaaa yes yes
MODiX
MODiX3y ago
Diddy#2634
REPL Result: Success
int x = 5;
if (x == 5) Console.WriteLine("Equal!");
int x = 5;
if (x == 5) Console.WriteLine("Equal!");
Console Output
Equal!
Equal!
Compile: 582.625ms | Execution: 33.080ms | React with ❌ to remove this embed.
hercules_x_x
hercules_x_xOP3y ago
let me try First i will declare toe arrays then i will do the calculation u ask me wait please but i am confused there is tow type of array which one i declare
mtreit
mtreit3y ago
What do you mean exactly?
hercules_x_x
hercules_x_xOP3y ago
type 1.....int[,] arr = new int[,]{{1,2,3},{4,5,6},{7,8,9}}; type2...• int[] arr = new int[5]{ 10, 20, 30, 40, 50 }; how i knows in he future if he want the first type? 2d array?
mtreit
mtreit3y ago
Multi-dimensional arrays are kind of special purpose - like for defining a grid or matrix. Most uses of arrays are the single dimensional kind.
hercules_x_x
hercules_x_xOP3y ago
int[] arr = { 10, 20, 30, 40, 50 }; int[] arr1 = { 5, 22, 63, 70, 80 }; if(arr == arr1) System.Console.WriteLine("they are equal"); else { System.Console.WriteLine("they are not equal"); }
hercules_x_x
hercules_x_xOP3y ago
this better
Kouhai
Kouhai3y ago
Unfortunately this way of checking array content's equality wouldn't work in c#
hercules_x_x
hercules_x_xOP3y ago
i am using Visual Studio then how to make it work in c# ohhhh yes in this uni must Visual studio code i had long dilemma with the teacher end up his winning and my lost lol hmmm i am confused how to do thta that yes ohhhh so array cant because not specific number yes there is arr.length ? but how to cod it nicely OhNo me try
hercules_x_x
hercules_x_xOP3y ago
like that?
hercules_x_x
hercules_x_xOP3y ago
feels wrong
hercules_x_x
hercules_x_xOP3y ago
i try this too
hercules_x_x
hercules_x_xOP3y ago
but obviously wrong hard OhNo
Kouhai
Kouhai3y ago
In an if statement you'll do (expression) == (expression) expression here can be any value or variable So the first expression you have is arr=arr.Length second expression arr1=arr1.Length What these expressions mean They mean assign arr.Length to arr and assign arr1.Length to arr1 That obviously wouldn't work because 1- arr1 and arr1.Length have different types 2- the expressions can't be compared
hercules_x_x
hercules_x_xOP3y ago
i am just a little confused now lol then how
hercules_x_x
hercules_x_xOP3y ago
now?
hercules_x_x
hercules_x_xOP3y ago
it must be this Visual headache i kill u slowly program
hercules_x_x
hercules_x_xOP3y ago
hercules_x_x
hercules_x_xOP3y ago
if {} ? so if can be () and {} what is the difference ? i notice for loop (FOR) always ()
hercules_x_x
hercules_x_xOP3y ago
like this
hercules_x_x
hercules_x_xOP3y ago
ok ok noted and elements with same index from both arrays are same. what is that i don’t understand index, ohhhhh i have an idea yea so in q want me to delete. i didn’t know that the rest of the q yes i am trying
MODiX
MODiX3y ago
Diddy#2634
REPL Result: Success
int[] arr = { 10, 20, 30, 40, 50 };

int value = arr[1]; // 2nd element in array since arrays start at 0

Console.WriteLine(value);
int[] arr = { 10, 20, 30, 40, 50 };

int value = arr[1]; // 2nd element in array since arrays start at 0

Console.WriteLine(value);
Console Output
20
20
Compile: 573.979ms | Execution: 64.356ms | React with ❌ to remove this embed.
hercules_x_x
hercules_x_xOP3y ago
is this real person ? ok following u if ? if(arr[0] ==arr1[0]); ? heheh u are amazing teacher ok ohhh yea yea then how for(int a=0; a=<5; a++) yes sooo ok for(arr[,]=0; arr[,]=>....... i can’t figure the rest nested loop ?
MODiX
MODiX3y ago
Diddy#2634
REPL Result: Success
// Has 5 elements
int[] arr = { 10, 20, 30, 40, 50 };

// You could replace the 5 here with the array length??
for (int i = 0; i < 5; i++)
{
Console.WriteLine($"Array[{i}] = {arr[i]}");
}
// Has 5 elements
int[] arr = { 10, 20, 30, 40, 50 };

// You could replace the 5 here with the array length??
for (int i = 0; i < 5; i++)
{
Console.WriteLine($"Array[{i}] = {arr[i]}");
}
Console Output
Array[0] = 10
Array[1] = 20
Array[2] = 30
Array[3] = 40
Array[4] = 50
Array[0] = 10
Array[1] = 20
Array[2] = 30
Array[3] = 40
Array[4] = 50
Compile: 648.189ms | Execution: 73.027ms | React with ❌ to remove this embed.
mtreit
mtreit3y ago
Can you write this exact same loop but make it go as many times as there are items in the array?
hercules_x_x
hercules_x_xOP3y ago
why $
MODiX
MODiX3y ago
Diddy#2634
REPL Result: Success
// Has 5 elements
int[] arr = { 10, 20, 30, 40, 50 };

// You could replace the 5 here with the array length??
for (int i = 0; i < 5; i++)
{
var currentIndex = i;
var currentArrayValue = arr[i];
Console.WriteLine($"Array[{currentIndex}] = {currentArrayValue}");
}
// Has 5 elements
int[] arr = { 10, 20, 30, 40, 50 };

// You could replace the 5 here with the array length??
for (int i = 0; i < 5; i++)
{
var currentIndex = i;
var currentArrayValue = arr[i];
Console.WriteLine($"Array[{currentIndex}] = {currentArrayValue}");
}
Console Output
Array[0] = 10
Array[1] = 20
Array[2] = 30
Array[3] = 40
Array[4] = 50
Array[0] = 10
Array[1] = 20
Array[2] = 30
Array[3] = 40
Array[4] = 50
Compile: 723.539ms | Execution: 72.182ms | React with ❌ to remove this embed.
hercules_x_x
hercules_x_xOP3y ago
i will try this i dont understand what he mean put the last index number hmmm how ya lol arr.lengthlast arr.lenght-1
mtreit
mtreit3y ago
Oh your loop I commented on isn't actually correct =< Thats not a thing Just use <
hercules_x_x
hercules_x_xOP3y ago
so for(arr[] < arr.length-1 ? or just follow this lol for(i=0; i=>arr.length-1; i++) var currentIndex = i; var currentArrayValue = arr[i]; ok i am officially lost can just explain this to me
mtreit
mtreit3y ago
You need to study how for loops work And learn what operators are valid => is not a valid operator in a for loop You want the less than operator
hercules_x_x
hercules_x_xOP3y ago
<= i mean this
mtreit
mtreit3y ago
Yes that's better Although we usually do: i < arr.Length instead of i <= arr.Length - 1
hercules_x_x
hercules_x_xOP3y ago
ohhhh yesss
hercules_x_x
hercules_x_xOP3y ago
Finally
hercules_x_x
hercules_x_xOP3y ago
thanks for everything
Kouhai
Kouhai3y ago
You're still not checking whether they are equal or not.
Want results from more Discord servers?
Add your server