Cannot implicitly convert type 'string' to 'string[]'
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Cannot implicitly convert type 'string' to 'string[]'

  1. #1
    Join Date
    Jun 2014
    Posts
    1

    Unhappy Cannot implicitly convert type 'string' to 'string[]'

    Hello!
    I have a rich text Box field named "txtReadfile" in which i load ea text file having possibly many word.
    now i want to store the text from "txtReadfile" in a string array for further process, but when i try to do so by using the following code it give me an error "Cannot implicitly convert type 'string' to 'string[]' "

    string[] arrTxtReadfile = txtReadfile.Text.ToString();


    Please Help. thanks in Advance

  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,485

    Re: Cannot implicitly convert type 'string' to 'string[]'

    A string and a string array are two different things.

    When you call .ToString() on an object, it creates a [single] string, not a string array.

    To fix declare string[] arrTxtReadFile without the [].

  3. #3
    Join Date
    Jun 2014
    Posts
    4

    Re: Cannot implicitly convert type 'string' to 'string[]'

    Quote Originally Posted by Wahab_Phd View Post
    Hello!
    now i want to store the text from "txtReadfile" in a string array for further process
    If I get what you are trying to do, you want to store multiple strings for further process?

    I believe you should use a List<string>, a Stack<string> or a Queue<string>. This way, you can store multiple strings without having to redimension an everytime.

    Hope this helps!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center