49

When the string[], _lineParts is added to the List, all I see in the List is "System.String[]" What needs to be done to see the actually string[] values in the list.

while (_aLine != null) 
{ 
    //split the line read into parts delimited by commas 
    _lineParts = _aLine.Split(new char[] { ' ', '\u000A', ',', '.', ';', ':', '-', '_', '/' }, 
        StringSplitOptions.RemoveEmptyEntries); 
    //keep things going by reading the next  line 
    _aLine = sr.ReadLine(); 
    //words = _lineParts; 
    if (_lineParts != null) 
    { 
        //_words.Add(_lineParts.ToString()); 
        wrd.Add(_lineParts.ToString()); 
    } 
} 
2
  • 1
    You're not adding _lineParts to the list, you're adding _lineParts.ToString() to the list. The default behavior of ToString() for reference types is to output the type name, which in this case is System.String[]. Are you trying to add each individual element from the array to the list? Or are you trying to add the entire array as a single element to the list? Commented Oct 14, 2012 at 13:46
  • Each individual element from array to list. Commented Oct 14, 2012 at 13:50

3 Answers 3

85

Use List.AddRange instead of List.Add

Sign up to request clarification or add additional context in comments.

Comments

27

Use List.AddRange instead of List.Add

Change

 wrd.Add(_lineParts.ToString());

To

wrd.AddRange(_lineParts);

1 Comment

nice - suddenly i remember why i love javascript :-P
5

You can use List.AddRange() where you are using List.Add()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.