新手入门,大家帮看下下面这个代码是哪里出错了
系统提示说错误 1 当前上下文中不存在名称“persons” 前面明明定义了一个集合‘persins'的,,想不明白是哪里写错了
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace WindowsFormsApplication1
{
public partial class SayHi : Form
{
public SayHi()
{
InitializeComponent();
}
class PersonInfo
{
public string Name { get; set; }
public char Sex { get; set; }
public int Age { get; set; }
public PersonInfo(string name, char sex, int age)
{
this.Name = name;
this.Sex = sex;
this.Age = age;
}
}
class Sample
{
List<PersonInfo> persons = new List<PersonInfo> //定义persons集合
{
new PersonInfo("赵灵儿",'女',16),
new PersonInfo("林月如",'男',18),
new PersonInfo("李逍遥",'女',22),
new PersonInfo("一如",'女',7),
};
}
private void btnCount_Click(object sender, EventArgs e)
{
var orderBy = persons.Select //提示说上下文没有“persons"这个名称
(name => "你好!" + name)
.OrderBy(name => name.Sustring(0, 1));
string nameList = "";
foreach (var item in orderBy)
{
nameList += item + "\t";
}
MessageBox.Show(nameList);
}
}
}