当前位置: 首页>>代码示例>>C#>>正文


C# Student.Where方法代码示例

本文整理汇总了C#中Student.Where方法的典型用法代码示例。如果您正苦于以下问题:C# Student.Where方法的具体用法?C# Student.Where怎么用?C# Student.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Student的用法示例。


在下文中一共展示了Student.Where方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FirstLastNameCompare

 private static Student[] FirstLastNameCompare(Student[] students)
 {
     return students
         .Where(x => x.FirstName.CompareTo(x.LastName) < 0)
         .Select(x => x)
         .ToArray<Student>();
 }
开发者ID:p0150n,项目名称:TelerikAcademy,代码行数:7,代码来源:FirstBeforeLast.cs

示例2: Main

        static void Main()
        {
            Random rand = new Random();
            Student[] students = new Student[10];
            string[] firstNames = new string[] { "Niki", "Doncho", "Pesho", "Maria", "Stamat", "Ivan", "Ivo", "Gosho", "Evlogi", "Svetlin" };
            string[] lastNames = new string[] { "Kostov", "Minkov", "Peshev", "Ivanov", "Stamatov", "Popov", "Kenov", "Goshev", "Hristov", "Nakov" };

            for (int i = 0; i < students.Length; i++)
            {
                string firstName = firstNames[rand.Next(0, 10)];
                string lastName = lastNames[rand.Next(0, 10)];
                int fn = int.Parse(rand.Next(1000, 9999).ToString() + "0" + rand.Next(1, 7));
                Student student = new Student(firstName, lastName, fn);
                for (int j = 0; j < 6; j++)
                {
                    student.Marks.Add(rand.Next(3, 7));
                }
                students[i] = student;
            }

            var studentsMarks = students.Where(st => st.FacultyNumber % 100 == 6).Select(st => new { fn = st.FacultyNumber, st.Marks }).ToList();

            foreach (var student in studentsMarks)
            {
                Console.WriteLine("fn-{0}, marks-{1}",student.fn, string.Join(",",student.Marks));
            }
        }
开发者ID:VDGone,项目名称:TelerikAcademy-1,代码行数:27,代码来源:ExtractMarks.cs

示例3: FirstBeforeLast

 // METHODS
 public static Student[] FirstBeforeLast(Student[] students)
 {
     return students.Where(x => x.FirstName.CompareTo(x.LastName) < 0).ToArray();
 }
开发者ID:tddold,项目名称:Telerik-Academy-Homework-Solutions,代码行数:5,代码来源:Student.cs

示例4: Main

    static void Main()
    {
        //Problem 1. Class Student
        var students = new Student[]
            {
                new Student("Ivan", "Petrov", 20, "1234140", "089945769238", "[email protected]", new List<int>{2,2,2,4}, 1),
            new Student("Maria", "Ignatova", 21, "8893746", "0264564708", "[email protected]", new List<int>{3,4,6}, 2),
             new Student("Simeon", "Todorov", 25, "563437", "+359266743508", "[email protected]", new List<int>{5,6,6}, 6),
             new Student("Asen", "Dimov", 27, "523414466", "08882479360", "[email protected]", new List<int>{5,4,6}, 2)
            };

        //Problem 2. Students by Group
        var groupTwo =
            from st in students
            where st.GroupNumber == 2
            orderby st.FirstName
            select st;
        Console.WriteLine("Students from group two:");
        foreach (var item in groupTwo)
        {
            Console.WriteLine("First Name: {0}, Last Name:{1}, Age:{2}, Faculty Number:{3}, Phone:{4}, Email:{5}, Grades:{6}", item.FirstName, item.LastName, item.Age, item.FacultyNumber, item.Phone, item.Email, string.Join(",", item.Marks));
        }
        Console.WriteLine();
        //Problem 3. Students by First and Last Name
        var firstAndLastName =
            from st in students
            where st.FirstName[0] < st.LastName[0]
            select st;

        Console.WriteLine("Students by First and Last Name:");
        foreach (var item in firstAndLastName)
        {
            Console.WriteLine("First Name: {0}, Last Name:{1}, Age:{2}, Faculty Number:{3}, Phone:{4}, Email:{5}, Grades:{6}", item.FirstName, item.LastName, item.Age, item.FacultyNumber, item.Phone, item.Email, string.Join(",", item.Marks));
        }
        Console.WriteLine();

        //Problem 4. Students by Age
        var studentsByAge =
                from st in students
                where st.Age >= 18 && st.Age <= 24
                select new { st.FirstName, st.LastName };

        Console.WriteLine("Students By Age:");
        foreach (var item in groupTwo)
        {
            Console.WriteLine("First Name: {0}, Last Name:{1}", item.FirstName, item.LastName);
        }
        Console.WriteLine();

        //Problem 5. Sort Students
        //LINQ query syntax
        var sortStudents =
                   from st in students
                   orderby st.FirstName descending,
                   st.LastName descending
                   select st;

        Console.WriteLine("Sort Students:");
        foreach (var item in sortStudents)
        {
            Console.WriteLine("First Name: {0}, Last Name:{1}", item.FirstName, item.LastName);
        }
        Console.WriteLine();
        //Extension methods
        var sortStudentsByNames = students.OrderByDescending(st => st.FirstName).ThenByDescending(st => st.LastName);

        Console.WriteLine("Sort Students:");
        foreach (var item in sortStudentsByNames)
        {
            Console.WriteLine("First Name: {0}, Last Name:{1}", item.FirstName, item.LastName);
        }
        Console.WriteLine();

        //Problem 6. Filter Students by Email Domain
        var sortStudentsByEmail = students.Where(st => st.Email.EndsWith("abv.bg"));

        Console.WriteLine("Sort Students By Email:");
        foreach (var item in sortStudentsByEmail)
        {
            Console.WriteLine("First Name: {0}, Last Name:{1}", item.FirstName, item.LastName);
        }
        Console.WriteLine();

        //Problem 7. Filter Students by Phone
        var sortStudentsByPhone = students.Where(st => st.Phone.StartsWith("02") || st.Phone.StartsWith("+3592") || st.Phone.StartsWith("+359 2"));

        Console.WriteLine("Sort Students By Phone:");
        foreach (var item in sortStudentsByPhone)
        {
            Console.WriteLine("First Name: {0}, Last Name:{1}, Phone:{2}", item.FirstName, item.LastName, item.Phone);
        }
        Console.WriteLine();

        //Problem 8. Excellent Students
        var excellentStudents = students.Where(st => st.Marks.Any(c => c == 6));

        Console.WriteLine("Excellent Students:");
        foreach (var item in excellentStudents)
        {
            Console.WriteLine("First Name: {0}, Last Name:{1}", item.FirstName, item.LastName);
//.........这里部分代码省略.........
开发者ID:PlamenaMiteva,项目名称:CSharp_Advanced,代码行数:101,代码来源:1-10+Homework+Problems.cs

示例5: AgeRange

 public static Student[] AgeRange(Student[] students, int low, int high)
 {
     return students.Where(x => x.Age > low && x.Age < high).ToArray();
 }
开发者ID:tddold,项目名称:Telerik-Academy-Homework-Solutions,代码行数:4,代码来源:Student.cs


注:本文中的Student.Where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。