相关文章推荐
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

This code works fine on wpf.

In my code list1 will work but if convert a string to a list of char and change again to string it showing error of : can't convert from char[] to string []. need suggestion.

here's the code :

        string x = "hello";
        List<char> list = x.ToList<char>();
        //error
        string combindedString = string.Join(",", list.ToArray());
        string xz = string.Join("", list);
        //---
        //okay....
        List<string> list1 = new List<string>()
                                    "Red",
                                    "Blue",
                                    "Green"
        string output = string.Join("", list1.ToArray());
                Ahhh you're using the old version of Unity. That version used .Net 3.5 when a char[] didn't implement IEnumerable<char>
– JSteward
                Jul 25, 2018 at 0:25

Well I suspect the source of your issue still lies with using the older .Net Framework that is default with Unity, 3.5 I believe. You have some options, to work around the problem though:

  • You can target an update framework, I believe Unity supports up to 4.6.1 in experimental mode.

  • You can work around converting a char[] to string.

  • Or just use the string constructor:

  • A simple example:

    [Test]
    public void StringTest()
        string x = "hello";
        List<char> list = x.ToList<char>();
        string newStr = new string(list.ToArray());
        Assert.IsTrue(newStr == x);
                    Another way you might try is to convert the list<char> into an array<char> and then create a string like so: string original = new string(array<char>); Not sure how well that would do on performance though :) You didn't mention that in your post
    – Zachary Watson
                    Jul 25, 2018 at 0:50
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

     
    推荐文章