+ 2

Array's vs Collection in c#

I am a huge fan of Collections. I write my programs in c#. I like collections because they can change size at run-time and you can easily add and remove elements. In C# When do you prefer to use array's instead of collection.

10th Apr 2019, 8:32 PM
sneeze
sneeze - avatar
3 Antworten
+ 1
Interesting question... I think array more convenient when we need a static range. In example when i create temperature meter device on MCU i use array for create conformity tables to match ADC value with temperature curve. I think in this example - list is not convenient... double[] temper = {-50,-40,-30,-20,-10,etc}; double[] AdcVal = {0.125,0.4,0.7,0.9,1.1,etc}; And after i create a curve from this value . And one more , some element used array , for example - string is array of char, so if this function is already implemented in the system - why not let it be used. It's my opinion...
13th Apr 2019, 9:38 AM
id001x
id001x - avatar
+ 1
Thanks. I am properly not aware of how many times people do work with static ranges. Most of the ranges I work differ a lot in size.
13th Apr 2019, 7:38 PM
sneeze
sneeze - avatar
0
Arrays are fixed size, when you declare the arrays you need to define the size, where as collection are dynamic they will grow automatically based on the requirement
12th Apr 2020, 5:58 PM
vinod kumar
vinod kumar - avatar