C
C#•2y ago
Uvuv

Array exception

I can't for the life of me figure out this exception. ive identified that it comes from neurons because of it not actually appending the jagged array. Im sure this is something im misunderstanding with C#, maybe something with ownership?
No description
No description
13 Replies
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle•2y ago
what you're missing is .Append doesn't mutate the source collection, it produces an enumerable that represents the contents of that collection with the appended item at the end C# arrays can't be resized automatically, if you want that behavior use Lists with .Add instead
Uvuv
UvuvOP•2y ago
im translating that ot mean its something like python, where 99.9% of functions to change things return the changed value that you then set the original variable equal to
Jimmacle
Jimmacle•2y ago
in this specific case with .Append, yes that method is part of LINQ which is a collection of functions to filter/map collections
Uvuv
UvuvOP•2y ago
i c so would i have a list of lists of neurons
Jimmacle
Jimmacle•2y ago
yes
Uvuv
UvuvOP•2y ago
aight bet
Jimmacle
Jimmacle•2y ago
lists are essentially arrays but they automatically get bigger when you add items
Uvuv
UvuvOP•2y ago
c++ equiv of vector
Jimmacle
Jimmacle•2y ago
yeah
Uvuv
UvuvOP•2y ago
and then arrays are basically the same between c# and c++ at least in application dubs
🥄feeders help me learn faster !
In C++, array cannot be assigned directly to another array.
// c++
int p[] = { 1,2 };
int q[2];
// q = p; // Error
memcpy(q, p, sizeof(p));
// c++
int p[] = { 1,2 };
int q[2];
// q = p; // Error
memcpy(q, p, sizeof(p));
But in C#, it is ok.
// c#
int[] p = {1, 2};
int[] q = p;
// c#
int[] p = {1, 2};
int[] q = p;
Jimmacle
Jimmacle•2y ago
it would be a more realistic comparison to use pointers and C# references are more like pointers than stack allocated variables

Did you find this page helpful?