C
C#10mo ago
HD-Fr0sT

what is the difference between arrays,vectors and lists?

and what are the different use cases
14 Replies
jcotton42
jcotton4210mo ago
generally arrays are fixed in size, cannot be grown or shrunk list and vector are resizable, and are usually the same thing conceptually some languages like Rust and C++ use the term Vector, others like Java, Python, C# use the term List
HD-Fr0sT
HD-Fr0sTOP10mo ago
cant arrays be set in variable size?
jcotton42
jcotton4210mo ago
well, are you talking about arrays in .NET specifically, or arrays in general?
HD-Fr0sT
HD-Fr0sTOP10mo ago
in general
jcotton42
jcotton4210mo ago
also what do you mean "variable size"? like you can do new int[mySize]; but the array will always be mySize in length, can't be grown later
HD-Fr0sT
HD-Fr0sTOP10mo ago
yep
jcotton42
jcotton4210mo ago
yeah that's just fine
HD-Fr0sT
HD-Fr0sTOP10mo ago
are list and vector mutable/dynamic?
jcotton42
jcotton4210mo ago
var i = 3;
var array = new int[i];
var list = new List<int>(i);
array.Add(83); // not valid
list.Add(38); // valid, list now has a length of 4
var i = 3;
var array = new int[i];
var list = new List<int>(i);
array.Add(83); // not valid
list.Add(38); // valid, list now has a length of 4
Jimmacle
Jimmacle10mo ago
they're all mutable, as far as C# is concerned the difference between an array and list is a list dynamically resizes to hold more items there's no collection in C# called a vector
333fred
333fred10mo ago
There kind of is, but it refers to the mathematical term "vector", not what C++ or Rust mean by the word Isn't English fun?
Thinker
Thinker10mo ago
vector (game dev) != vector (computing) != vector (data structures)
HD-Fr0sT
HD-Fr0sTOP10mo ago
Like the 2d matrix stuff?
333fred
333fred10mo ago
Yes
Want results from more Discord servers?
Add your server