Converting a list to an array with ToArray()

孤者浪人 提交于 2019-12-03 13:05:16

This is the error (as pointed out from Darkshadw and Jon Skeet)

listItem myList = new List<listItem>();

You are assigning the value of a List to a listItem.

Replace it with

List<listItem> myList = new List<listItem>();

to create a list of listItem. Then

listItem[] myArray = myList.ToArray();

will work.

have you tried

listItem[] myArray = myList.ToArray(new listItem[]{});

in Java it works, im not sure in c#

string[] s = myList.ToArray();

Considering myList is list of string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!