0

I am starting c#, and from what i read lists<> are most often preffered. But i kind use to; to think in arrays from my PLC coding past. I work a lot with blackwhite raw instrument image data. Which i currently put in a color array ea BWcolor[x,y] = 255;

it could also be done with lists in which the same point could be defined as element nr: x+stride * y

I wonder should i convert image handling to use list data or keep thinking in arrays. Because i read about that arrays should not be used in most cases. And that lists are faster?; or are lists in general better since lists have more buildin functions ? (like inserting elements). And if thats so it would only be handy to code so if my functions would depend on their functions.

I not realy get it why a lists are prefered when thinking in 2dimensional spaces, but if it is beneficial i would better start converting my code to use lists.

Peter
  • 1,706
  • 15
  • 35
  • 1
    _Because i read about that arrays should not be used in most cases. And that lists are faster?_ arrays are faster.note that list have array inside its implemention. if number of elements or indexes are dynamic then use list otherwise use array. – M.kazem Akhgary Oct 10 '15 at 17:32
  • It depends on the operations you are going to perform. For example if you want to insert an item in middle list will perform better. Check this https://msdn.microsoft.com/en-us/library/9ct4ey7x(v=vs.90).aspx#Anchor_1 – singsuyash Oct 10 '15 at 17:33
  • 1
    discussed already http://stackoverflow.com/questions/434761/array-versus-listt-when-to-use-which – singsuyash Oct 10 '15 at 17:35
  • 1
    As long as you stay far away from using `ArrayList`, you're fine. – C.Evenhuis Oct 10 '15 at 17:38
  • The difference you mention with stride etc is more of a 1D vs 2D thing. You could as well have a list of lists and index that with two "dimensions". But do use arrays when arrays are best, for example with predefined sized image data. – Sami Kuhmonen Oct 10 '15 at 17:42
  • 1
    _"from what i read lists<> are most often preffered"_ -- what have you been reading, that you would get such unhelpful advice? Bottom line: generally, there are good reasons to use both, and it "just depends". For image data, you are unlikely to be able to use lists successfully in any useful way because lists are not inherently two-dimensional. You can only implement "jagged" structures using lists, and these won't be compatible with any image-handling API. – Peter Duniho Oct 10 '15 at 18:27
  • well i've been reading various articles, about programming and every time lists where adviced. So i got confused, i think i have to use them for anything that is 1 dimensional (ea row of numbers), but for 2D i wasnt sure; i'm writing my own image methods so i'm not depending on other API's. from what i understand here i can just go on using array's theyre fine – Peter Oct 10 '15 at 18:46

0 Answers0