I ask this question out of sheer curiosity. I don’t have any actual code to ponder over.
Is there a best-case scenario for using a jagged array instead of a list of lists, and vice versa?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
a
List<T>is an array, just a wrapped in a class so it can reallocate and resize it at will. So otherwise performance between the two can be considered identical – only useList<List<T>>if you need to resize either dimension – don’t forget that whenever you resize the 0th dimension you’ll need to construct new instances in the 1st dimension, which can be expensive.You forgot n-dimensional arrays (i.e.
T[,]). However, due to a quirk in .NET’s bounds-checking these are actually slower than jagged arrays or single-dimensional-user-managed arrays, which is a complete mystery.