LinQ简单使用

发布时间:2020-06-17 21:27:12 作者:a3309548
来源:网络 阅读:321

第一次写,主要是为了记录下自己的学习过程

  1. 创建一个学生类

    public class Student

    {

        public string username { get; set; }

        public int age { get; set; }

        public string sex { get; set; }

    }

2.创建数据方法

 public List<Student> Getstudent(int n)

    {

            List<Student> stuList = new List<Student>();

            for (int i = 0; i < n; i++)

            {

                Student stu = new Student();

                stu.age = 25 + i;

                stu.sex = "男" + i;

                stu.username = "张三" + i;

                stuList.Add(stu);

            }

            return stuList;

     }

3.在需要操作数据的方法调用 创建数据

  List<Student> student = Getstudent(10);

4.使用foreach来调试

 int n=33;//过滤值

 foreach (Student s in (from data in student where (data.age > n) select data))

    {

                Console.WriteLine(s.age);

    }


推荐阅读:
  1. netstat简单使用
  2. ansible简单使用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linq 简单使用

上一篇:访问phpmyadmin错误

下一篇:读Effective Objective C总结(一)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》