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


C# Student.OrderByDescending方法代码示例

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


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

示例1: Main

    static void Main(string[] args)
    {
        Student[] arrStudents = new Student[]
        {
            new Student() {Name = "Pesho", Family = "Ivanov", Age = 23},
            new Student() {Name = "Asen", Family = "Petkov", Age = 27},
            new Student() {Name = "Petar", Family = "Zlatev", Age = 28},
            new Student() {Name = "Asen", Family = "Borisov", Age = 28},
            new Student() {Name = "Desko", Family = "Borisov", Age = 28},
            new Student() {Name = "Desko", Family = "Arisov", Age = 28}
        };
        for (int i = 0; i < arrStudents.Length; i++)
        {
            Console.WriteLine(arrStudents[i]);
        }
        Console.WriteLine();
        var someStudents =
            from student in arrStudents
            orderby student.Name descending, student.Family descending
            select new Student { Name = student.Name, Family = student.Family, Age = student.Age };

        foreach (var item in someStudents)
        {
            Console.WriteLine(item);
        }
        Console.WriteLine();
        var someStudentsLambda =
            arrStudents.OrderByDescending(x => x.Name).ThenByDescending(x => x.Family);
        foreach (var item in someStudentsLambda)
        {
            Console.WriteLine(item);
        }
    }
开发者ID:stoyanovalexander,项目名称:TheRepositoryOfAlexanderStoyanov,代码行数:33,代码来源:Program.cs

示例2: SortStudentsByNameAndLastName1

 // Using the extension methods OrderBy() and ThenBy() with lambda expressions 
 // sort the students by first name and last name in descending order. Rewrite 
 // the same with LINQ.
 public static Student[] SortStudentsByNameAndLastName1(Student[] students) 
 {
     IEnumerable<Student> result = 
         students.OrderByDescending(x => x.FirstName)
         .ThenByDescending(x => x.LastName);            
     return result.ToArray(); 
 }
开发者ID:NikolayKostadinov,项目名称:Homeworks,代码行数:10,代码来源:Linq.cs

示例3: Main

    static void Main()
    {
        Student[] studentList = new Student[3];
        studentList[2] = new Student("Nadq", "Atanasova", 20);
        studentList[1] = new Student("Nadq", "Qnkova", 19);
        studentList[0] = new Student("Toshko", "Ivanov", 25);

        //Lambda expression
        Console.WriteLine("Lamda expression sort:");
        var sortedStudents = studentList.OrderByDescending(student => student.FirstName).ThenByDescending(student => student.LastName);
        foreach (Student student in sortedStudents)
        {
            Console.WriteLine("{0} {1}", student.FirstName, student.LastName);
        }
        Console.WriteLine();
        //LINQ Queries
        Console.WriteLine("LINQ Queries sort:");
        var LinqSortStudents =
            from student in studentList
            orderby student.FirstName descending, student.LastName descending
            select student;
        foreach (Student student in LinqSortStudents)
        {
            Console.WriteLine("{0} {1}", student.FirstName, student.LastName);
        }
    }
开发者ID:KirilToshev,项目名称:Projects,代码行数:26,代码来源:SortStudents.cs

示例4: Main

    static void Main()
    {
        Student[] arrayOfStudents = new Student[3];
        arrayOfStudents[0] = new Student("Ivan", "Todorov", 24);
        arrayOfStudents[1] = new Student("Petar", "Petrov", 16);
        arrayOfStudents[2] = new Student("Todor", "Ivanov", 20);

        var result = arrayOfStudents.
            OrderByDescending(student => student.FirstName).
            ThenByDescending(student => student.FamilyName).
            Select(student => string.Format("{0} {1}", student.FirstName, student.FamilyName));
        foreach (var item in result)
        {
            Console.WriteLine(item);
        }

        Console.WriteLine("-----------------------------");

        var wantedStudents = from student in arrayOfStudents
                             orderby student.FirstName descending, student.FamilyName descending
                             select string.Format("{0} {1}", student.FirstName, student.FamilyName);
        foreach (var item in wantedStudents)
        {
            Console.WriteLine(item);
        }
    }
开发者ID:VDGone,项目名称:TelerikAcademy-2,代码行数:26,代码来源:05.+SortStudentsByNames.cs

示例5: Main

        static void Main(string[] args)
        {
            Student st1 = new Student("Pesho", "Georgiev", 18);
            Student st2 = new Student("Pesho", "Yanakiev", 19);
            Student st3 = new Student("Rosen", "Ivanov", 14);
            Student st4 = new Student("Rosen", "Temelkov", 25);

            Student[] stArray = new Student[4];
            stArray[0] = st1;
            stArray[1] = st2;
            stArray[2] = st3;
            stArray[3] = st4;

            //with lambda expr
            var sortedQuery2 = stArray.OrderByDescending(x => x.FirstName).ThenByDescending(x => x.SecondName);

            foreach (var item in sortedQuery2)
            {
                Console.WriteLine(item.FirstName + " " + item.SecondName);
            }

            //with LINQ
            var sortedQuery1 =
                from student in stArray
                orderby student.FirstName descending, student.SecondName descending
                select student;

            foreach (var item in sortedQuery1)
            {
                Console.WriteLine(item.FirstName + " " + item.SecondName);
            }
        }
开发者ID:stefan-petrov,项目名称:TelerikAcademy,代码行数:32,代码来源:Test.cs

示例6: Main

    static void Main()
    {
        Student[] students = new Student[5];
        students[0] = new Student("Dobromir", "Ivanov", 18);
        students[1] = new Student("Serafim", "Jichkov", 9);
        students[2] = new Student("Evdoki", "Malinov", 35);
        students[3] = new Student("Pesho", "Petrov", 22);
        students[4] = new Student("Gosho", "Georgiev", 23);

        var searchedStudents = FindByAge(students);
        Console.WriteLine("Printing Students limited by age:");
        foreach (var student in searchedStudents)
        {
            Console.WriteLine(student);
        }

        Console.WriteLine("\nPrinting sorted students:");
        var sortedStudents = students.OrderByDescending(m => m.FirstName).ThenByDescending(m => m.LastName);
        foreach (var student in sortedStudents)
        {
            Console.WriteLine(student);
        }

        Console.WriteLine("\nPrinting sorted students with LINQ:");
        var sortedStudentsLINQ = from student in students
                             orderby student.FirstName descending, student.LastName descending
                             select student;
        foreach (var student in sortedStudentsLINQ)
        {
            Console.WriteLine(student);
        }
    }
开发者ID:nzhul,项目名称:TelerikAcademy,代码行数:32,代码来源:04-05-StudentByAgeTest.cs

示例7: Main

    static void Main()
    {
        Student[] myClass = new Student[3];

        Student firstStudent = new Student();
        firstStudent.firstName = "Ivan";
        firstStudent.secondName = "Zabunov";
        myClass[0] = firstStudent;

        Student secondStudent = new Student();
        secondStudent.firstName = "Teodor";
        secondStudent.secondName = "Andonov";
        myClass[1] = secondStudent;

        Student thirdStudent = new Student();
        thirdStudent.firstName = "Pesho";
        thirdStudent.secondName = "Olov";
        myClass[2] = thirdStudent;

        var sortedClass = myClass.OrderByDescending(x => x.firstName).ThenByDescending(x => x.secondName);

        foreach (var student in sortedClass)
        {
            Console.WriteLine("{0} {1}", student.firstName, student.secondName);
        }
    }
开发者ID:NikolaNikushev,项目名称:MyTelerikProjectsAndHomeworks,代码行数:26,代码来源:Program.cs

示例8: Main

    static void Main()
    {
        Console.WriteLine("Enter number of students");
        int number = int.Parse(Console.ReadLine());
        Student[] array = new Student[number];
        Console.WriteLine("Enter student first and last name separated by comma");
        for (int position = 0; position < number; position++)
        {
            string currentStudent = Console.ReadLine();
            string[] currentStudentNames = currentStudent.Split(',');
            array[position] = new Student(currentStudentNames[0], currentStudentNames[1]);
        }

        var sortedArray = array.OrderByDescending(x => x.FirstName).ThenByDescending(x => x.LastName);
        Console.WriteLine("Sorted students with lambda expression");
        foreach (var student in sortedArray)
        {
            Console.WriteLine("{0} {1}", student.FirstName, student.LastName);
        }

        var sortedStudents =
            from student in array
            orderby student.LastName descending
            orderby student.FirstName descending
            select student;

        Console.WriteLine("Sorted students with LINQ query");
        foreach (var student in sortedStudents)
        {
            Console.WriteLine("{0} {1}", student.FirstName, student.LastName);
        }
    }
开发者ID:vasilkrvasilev,项目名称:ObjectOrientedProgramming,代码行数:32,代码来源:SortByName.cs

示例9: DescendingOrder

 public static void DescendingOrder(Student[] allStudents)
 {
     var sorted = allStudents.OrderByDescending(x => x.FirstName).ThenByDescending(x => x.SecondName);
         foreach (var student in sorted)
         {
             Console.WriteLine("{0} {1}", student.FirstName, student.SecondName);
         }
 }
开发者ID:nikolaZ,项目名称:TelerikAcademy,代码行数:8,代码来源:Student.cs

示例10: OrderLambda

 public static void OrderLambda(Student[] students)
 {
     var newOrder = students.OrderByDescending(s => s.FirstName).ThenByDescending(s => s.LastName);
     foreach (var student in newOrder)
     {
         Console.WriteLine(student.FirstName + " " + student.LastName);
     }
 }
开发者ID:klimentt,项目名称:Telerik-Academy,代码行数:8,代码来源:Methods.cs

示例11: Main

        static void Main(string[] args)
        {
            Student[] ninjas = new Student[6];
            ninjas[0] = new Student("Mitko", "Georgiev", 20);
            ninjas[1] = new Student("Petar", "Kostov", 25);
            ninjas[2] = new Student("Mihail", "Georgiev", 18);
            ninjas[3] = new Student("Petar", "Petrov", 22);
            ninjas[4] = new Student("Nadq", "Stefanova", 27);
            ninjas[5] = new Student("Nadq", "Yanakieva", 21);

            var orderedStudents =
                from nin in ninjas
                where (nin.family.CompareTo(nin.name) > 0)
                select nin;

            var young =
                from nin in ninjas
                where (nin.age >= 18 && nin.age <= 24)
                select nin;

            var Alphabetic =
                ninjas.OrderByDescending(a => a.name).ThenByDescending(a => a.family);

            var Alphabetic2 =
                from nin in ninjas
                orderby nin.name descending, nin.family descending
                select nin;

          
            Console.WriteLine("problem 3");
            foreach (Student st in orderedStudents)
            {
                Console.WriteLine(st.name + "  " + st.family);
            }

            Console.WriteLine();
            Console.WriteLine("problem 4");
            foreach (Student st in young)
            {
                Console.WriteLine(st.name + "  " + st.family);
            }

            Console.WriteLine();
            Console.WriteLine("problem 5a");
            foreach (Student st in Alphabetic)
            {
                Console.WriteLine(st.name + "  " + st.family);
            }

            Console.WriteLine();
            Console.WriteLine("problem 5b");
            foreach (Student st in Alphabetic2)
            {
                Console.WriteLine(st.name + "  " + st.family);
            }
        }
开发者ID:Ivan-Dimitrov-bg,项目名称:.Net-framework,代码行数:56,代码来源:Students.cs

示例12: Main

    static void Main()
    {
        Student[] fewStudents = new Student[5];
          fewStudents[0] = new Student("Pesho", "Georgiev", 20);
          fewStudents[1] = new Student("Angel", "Ivanov", 22);
          fewStudents[2] = new Student("Mariq", "Petrova", 19);
          fewStudents[3] = new Student("Dodor", "Kirilov", 30);
          fewStudents[4] = new Student("Dragan", "Petkov", 45);

          var firstBeforeLast =
              from student in fewStudents
              where Convert.ToChar(student.FirstName.Substring(0, 1)) < Convert.ToChar(student.LastName.Substring(0, 1))
              select student;

          Console.WriteLine("Students whose first name is alphabetically before their last name are:");

          foreach (var student in firstBeforeLast)
          {
              Console.WriteLine("{0} {1}", student.FirstName, student.LastName);
          }

          var ageBetween =
              from student in fewStudents
              where student.Age >= 18 && student.Age <= 24
              select student;

          Console.WriteLine("Students in the age between 18 and 24 are:");

          foreach (var student in ageBetween)
          {
              Console.WriteLine("{0} {1} {2}",student.FirstName,student.LastName,student.Age);
          }

          Console.WriteLine("Students sorted in descending order by first name and the by last name:");
          var orderedByNamesDescending = fewStudents.OrderByDescending(x => x.FirstName).ThenByDescending(x => x.LastName);
          //first way
          foreach (var item in orderedByNamesDescending)
          {
              Console.WriteLine("{0} {1} {2}",item.FirstName,item.LastName,item.Age);
          }

          Console.WriteLine("Same with LINQ:");
          //second way with LINQ
          var orderedSecondway =
              from student in fewStudents
              orderby student.FirstName descending,student.LastName descending
              select student;
          foreach (var item in orderedSecondway)
          {
              Console.WriteLine("{0} {1} {2}", item.FirstName, item.LastName, item.Age);
          }
    }
开发者ID:peterlambov,项目名称:CSharp,代码行数:52,代码来源:OperationWithStudents.cs

示例13: Main

    static void Main()
    {
        Student[] students = new Student[3]{
            new Student("Bill", "Gates", 57),
            new Student("Mark", "Zuckerberg", 28),
            new Student("Other", "Name", 18)
        };

        //Task 3
        var getNames = from student in students
                      where student.FirstName.CompareTo(student.LastName) == -1
                      select student;

        foreach (var item in getNames)
        {
            Console.WriteLine("{0} {1}", item.FirstName, item.LastName);
        }

        Console.WriteLine();
        Console.WriteLine(new string('-', 25));
        Console.WriteLine();

        //Task 4
        var findAgeBetween18And24 = from student in students
                      where student.Age >= 18 && student.Age <= 24
                      select student;

        foreach (var item in findAgeBetween18And24)
        {
            Console.WriteLine("{0} {1}", item.FirstName, item.LastName);
        }

        Console.WriteLine();
        Console.WriteLine(new string('-', 25));
        Console.WriteLine();

        //Task 5
        var sortedNamesLinq = students.OrderByDescending(x => x.FirstName).ThenByDescending(x => x.FirstName);

        //Task 5 (rewrite)
        var sortedNames = from student in students
                          orderby student.FirstName descending, student.LastName descending
                          select student;

        foreach (var item in sortedNames)
        {
            Console.WriteLine("{0} {1}", item.FirstName, item.LastName);
        }
    }
开发者ID:hristian-dimov,项目名称:TelerikAcademy,代码行数:49,代码来源:StudentTest.cs

示例14: Main

        public static void Main()
        {
            var students = new Student[]
            {
               new Student("Pesho", "Ivanov", 22),
               new Student("Atanas", "Georgiev", 21),
               new Student("Stefan", "Atanasov", 25),
               new Student("Anton", "Atanasov", 18),
               new Student("Anton", "Petrov", 22),
               new Student("Dimitar", "Penev", 24)
            };

            // Problem 3
            // var namesFiltered = students.Where(st => st.FirstName.CompareTo(st.LastName)<=0).ToList();
            var namesFiltered = from st in students
                                where st.FirstName.CompareTo(st.LastName) <= 0
                                select st;
            Console.WriteLine("All students whose first name is before its last name alphabetically:");
            Console.WriteLine(string.Join(", ", namesFiltered));
            Console.WriteLine();

            // Problem 4
            // var ageFiltered = students.Where(st => st.Age >= 18 && st.Age <= 24).ToList();
            var ageFiltered = from st in students
                                where st.Age >= 18 && st.Age <= 24
                                select st;

            Console.WriteLine("All students with age between 18 and 24.");
            Console.WriteLine(string.Join(", ", ageFiltered));
            Console.WriteLine();

            // problem 5
            var sortedByNameLambda = students.OrderByDescending(st => st.FirstName).ThenByDescending(st => st.LastName);
            Console.WriteLine("Sort the students by first name and last name in descending order:");
            Console.WriteLine(string.Join(", ", sortedByNameLambda));
            Console.WriteLine();
            var sortedByNameLINQ = from st in students
                          orderby st.FirstName descending, st.LastName descending
                          select st;
            Console.WriteLine("Sort the students by first name and last name in descending order:");
            Console.WriteLine(string.Join(", ", sortedByNameLINQ));
            Console.WriteLine();
        }
开发者ID:emilti,项目名称:Telerik-Academy-My-Courses,代码行数:43,代码来源:OrderCheck.cs

示例15: Main

 static void Main()
 {
     Student[] arr = new Student[]
     {
         new Student("Annabell", "John", 26),
         new Student("Marin", "Petrov", 19),
         new Student("Marin", "Ivanov", 25),
         new Student("Maria", "Lilova", 19),
         new Student("Kalin", "Ivanov", 31)
     };
     //Task 3
     var students =
         from st in arr
         where st.FirstName.ToLower().First() < st.LastName.ToLower().First()
         select new Student(st.FirstName, st.LastName);
     foreach(Student st in students)
     {
         Console.WriteLine(st);
         Console.WriteLine();
     }
     //Task 4
     var studentsByAge =
         from st in arr
         where st.Age >= 18 && st.Age <= 24
         select new Student(st.FirstName, st.LastName);
     Console.WriteLine("Students between 18 and 24 years old");
     Console.WriteLine();
     foreach (Student st in studentsByAge)
     {
         Console.WriteLine(st);
         Console.WriteLine();
     }
     //Task 5
     arr = arr.OrderByDescending(st => st.FirstName).ThenByDescending(st => st.LastName).ToArray();
     Console.WriteLine("Sorted");
     Console.WriteLine();
     foreach (Student st in arr)
     {
         Console.WriteLine(st);
         Console.WriteLine();
     }
 }
开发者ID:PavDragneva,项目名称:TelerikAcademy,代码行数:42,代码来源:Test.cs


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