What is C # the most efficient Delphi TStringList analogue?

In our Delphi application, we use a TStringList to store strings and related objects. For another project, I need to do something similar in C #, but I'm not sure what the most efficient way to do this is. So far I have been thinking about using an array list, list, or dictionary. Will one of them be effective in what I want to do? If not, is this a good way to go?

+3
source share
6 answers

It depends on which TStringList functions you need. There really is no direct replacement.

A is dictionary<string,object>unordered and you cannot have duplicate rows. There is no Text property to set all lines at once, etc. If everything is okay with you, I would go for it.

Otherwise, you might consider defining a small class, for example:

public class Item { 
  public string String {get;set;} 
  public object Object {get;set;}
}

and then use List<Item>. This gives an ordered list of tuples (string, object).

+8
source

If the lines are unique, go to Dictionary<string, T>. If they are not guaranteed to be unique, the dictionary will not be suitable, and you may want to use a list Tuple<string, T>(C # 4) or, perhaps, a list KeyValuePair<string, T>that will be very similar to the dictionary, except obviously it does not guarantee uniqueness and preserves order when the dictionary does not will definitely do it.

Dictionary<string, T>> yourDictionary; // or
List<Tuple<string, T>> yourCollection; // or
List<KeyValuePair<string, T>> yourCollection;

, , .

+2

, . Dictionary<string, object> (generics).

+1

Dictionary<string,xxx>, xxx - , .

0

:

List<string>

, ( !):

ArrayList

. MSDN: 1, 2

0

Source: https://habr.com/ru/post/1787736/


All Articles