Ilist和list如何使用?

    protected void Page_Load(object sender, EventArgs e)
    {
        User u1 = new User();
        u1 = (User)getAllUser()[0];//人
        u1.LoginName = "people";
        u1.PassWord = "123456";
        u1.UserName = "I am Man";

        User u2 = (User)getAllUser()[1];//动物
        u2.LoginName = "animal";
        u2.PassWord = "123456";
        u2.UserName = "I am animal";

        string sql1=DAL.insert(u1);
        string sql2 = DAL.insert(u2);
    }


    public class DAL
    {
        public static string insert(User u)
        {
            string Sql = "insert into usertable (loginname,password,username) values ('" + u.LoginName + "','" + u.PassWord + "','" + u.UserName + "')";
            return Sql;
        }
    }


    public IList<User> getAllUser()
    {
        IList<User> li = new List<User>();//构建泛型接口
        User u = new User();//实例类
        User u2 = new User();//实例类
        li.Add(u);//人
        li.Add(u2);//动物
        return li;
    }
    //人物类
    public new class User
    {
        private string loginName;
        public string LoginName
        {
            get { return loginName; }
            set { loginName = value; }
        }
        private string password;
        public string PassWord
        {
            get { return password; }
            set { password = value; }
        }
        private string userName;
        public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }
    }

 1、请问以上代码 有何好处,为什么要这样用呢,(请具体指明,这样用有怎样的好处)

2、Ilist 换成List一样可以运行

3、不理解Ilist和list区别

 

谢谢

你可能感兴趣的:(sql,list,String,user,Class,insert)