473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

List<string> vs. string[]

Hi all,
what are the differences (performance, features, capabilities, etc.) between
a List of string and an array of string?
I'd like to know when it's better one or another (I'm using C# 2.0)

Thanks in advance.
--
Luigi
http://blogs.dotnethell.it/ciupaz/
Oct 13 '08 #1
2 2294
Unless you know your data is fixed size (which is quite rare), an array
is usually very prohibitive, since there is no Add/Remove. List<T>
itself also offers many additional methods compared to T[] - however,
you might not need them all for simple data like strings.

Working within an array will be marginally quicker (not much) since the
bounds checking is simpler and there is less abstraction (a List<T>
actually wraps a T[], so it can *only* get slower). In most cases, the
difference is negligible - and consider that adding data to an array
(i.e. increasing the size by 1 each time) is very slow compared to
List<T>'s doubling approach.

Marc
Oct 13 '08 #2
"Marc Gravell" wrote:
Unless you know your data is fixed size (which is quite rare), an array
is usually very prohibitive, since there is no Add/Remove. List<T>
itself also offers many additional methods compared to T[] - however,
you might not need them all for simple data like strings.

Working within an array will be marginally quicker (not much) since the
bounds checking is simpler and there is less abstraction (a List<T>
actually wraps a T[], so it can *only* get slower). In most cases, the
difference is negligible - and consider that adding data to an array
(i.e. increasing the size by 1 each time) is very slow compared to
List<T>'s doubling approach.

Marc
Thanks Marc, now it's clearer.

L
>
Oct 13 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: gbgbgbgb | last post by:
Hi, I have a definition bool operator<(string s_s, string s_t) { .... } and a variable list<string> concomp;
2
by: s | last post by:
I'm getting compile errors on the following code: <code> #include <iostream> #include <fstream> #include <list> #include <string> using namespace std;
3
by: aquanutz | last post by:
Ok, I have a list of strings (list<string> stringList) that I want to sort alphabetcially, only "sort(stringList.begin(), stringList.end()); ) does not work. Any insight would be helpful. Thanks!
3
by: Abhi | last post by:
In the following hypothetical example I want to build a generic list of unique string items. How should I implement the pred function so that it returns true/false if target string exists in the...
4
by: Mark Rae | last post by:
Hi, Is it possible to create a case-insensitive List<stringcollection? E.g. List<stringMyList = new List<string>; MyList.Add("MyString"); So that:
4
by: rsa_net_newbie | last post by:
Hi there, I have a Managed C++ object (in a DLL) which has a method that is defined like ... Generic::List<String^>^ buildList(String^ inParm) Now, when I compile it, I get "warning C4172:...
2
by: sjoshi | last post by:
Is List.ConvertAll the only way to apply TrimStart to elements of a List<stringor is there a better way ? Currently I'm doing this... List<stringlst = new List<string>(); lst.AddRange(new...
2
by: Assimalyst | last post by:
Hi I have a Dictionary<string, List<string>>, which i have successfully filled. My problem is I need to create a filter expression using all possible permutations of its contents. i.e. the...
4
by: parez | last post by:
Hi, I am trying to serialize List<List<string>. With the following code public List<List<string>DataRows { get; set; }
3
by: banangroda | last post by:
Compilation fails at "line.insert(line.end(), x.begin(), i);" and I can't figure out why. Here is the code: /* 5-1. Design and implement a program to produce a permuted index. A permuted index...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.