日期:2014-05-17  浏览次数:20443 次

ListItem数组问题
C# code

        ListItem[] schlist = new ListItem[db.GetTable<schInfo>().Count()];
        for (int i = 0; i < schlist.Length; i++)
        {
            foreach (var s in db.GetTable<schInfo>())
            {
                schlist[i].Text = s.schCode + "  " + s.schName;
                schlist[i].Value = s.schCode;
            }
            schCode.Items.Add(schlist[i]);
        }
        DataBind();


  我在运行到schlist[i].Text = s.schCode + " " + s.schName;这一句时,提示我未将对象引用设置到对象的实例。请各位帮忙解决一下

------解决方案--------------------
ListItem[] schlist = db.GetTable<schInfo>()
.Cast<schInfo>().Select(x => new ListItem() { Text = x.schCode + " " + x.schName, Value = x.schCode}).ToArray();
DataBind();