❔ ✅ C# lists
rather than using
.Add()
is there a way that i can put the array into myList in order to create the list from that32 Replies
oh
arr.ToList()
should also work, IIRCthanks guys
what is i wanted to loop through the list, would i use
arr.length
or myList.length
?
@implicit electron
huh
Or just
foreach
¯\_(ツ)_/¯Jester#8471
REPL Result: Success
Result: List<int>
Compile: 564.553ms | Execution: 34.230ms | React with ❌ to remove this embed.
This does not create a list from an array
you have a list without needing an array
the for loop i made looping through doesnt seem to work
What doesn't work about it?
ignore the class
Angius#1586
REPL Result: Failure
Exception: CompilationErrorException
Compile: 661.372ms | Execution: 0.000ms | React with ❌ to remove this embed.
.Count
Angius#1586
REPL Result: Success
Console Output
Compile: 641.923ms | Execution: 70.760ms | React with ❌ to remove this embed.
Alternatively...
what is .cout
.count*
A property
int[] arr = { 1, 2, 3 };
List<int> list = new List<int>();
list.AddRange(arr);
oh ok
Angius#1586
REPL Result: Success
Console Output
Compile: 607.012ms | Execution: 71.563ms | React with ❌ to remove this embed.
Use a
foreach
and never worry about Count/Length againah that works too
ok
welp thanks everyone
see he doesnt need an array but just a list
no i was converting the arr into a list then looping through
you can also loop trough an array
im guessing that i shouldn't use lists unless i really need them huh
yeah
ah ok
each type has their use
Lists are used when you need a dynamically-sized collection, so
.Add()
, .Remove()
, etcalright
Jester#8471
REPL Result: Success
Console Output
Compile: 595.764ms | Execution: 66.240ms | React with ❌ to remove this embed.
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.