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

[菜鸟求助]List,根据元素的部分内容找到元素的索引
  class student
        {
            public string no { get; set; }
            public string name { get; set; }
            public string tel { get; set; }
            public string address { get; set; }
            public override string ToString()
            {
                return string.Format("{0} {1} {2} {3}", no, 

name, tel, address);
            }
        }
 List<student> mylist = new List<student>();
 string current = textBox2.Text;
            int ci=  mylist.IndexOf((student)from a in mylist 

where a.name==current select a);
发生以下异常:
附:完整代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Collections;

namespace myconnect
{
   
    public partial class connect : Form
    {
        public connect()
        {
            InitializeComponent();
        }
        class student
        {
            public string no { get; set; }
            public string name { get; set; }
            public string tel { get; set; }
            public string address { get; set; }
            public override string ToString()
            {
                return string.Format("{0} {1} {2} {3}", no, name, tel, address);
            }
        }
        List<student> mylist = new List<student>();
        private void&