注册 登录
编程论坛 VB.NET论坛

请教LINQ问题

ppppooiiuu 发布于 2018-09-19 11:36, 1914 次点击
只有本站会员才能查看附件,请 登录

程序代码:

namespace ConsoleApp5
{
    public class Student
    {
        public string First { get; set; }
        public string Last { get; set; }
        public int ID { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            List<Student> students = new List<Student>
                    {
                       new Student {First="Svetlana", Last="Omelchenko", ID=111},
                       new Student {First="Claire", Last="O'Donnell", ID=112},
                       new Student {First="Sven", Last="Mortensen", ID=113},
                       new Student {First="Cesar", Last="Garcia", ID=114},
                       new Student {First="Debra", Last="Garcia", ID=115}
                    };

            var sortedGroups =
                from student in students
                orderby student.Last, student.First
                group student by student.Last[0] into newGroup
                orderby newGroup.Key
                select newGroup;
            Console.ReadKey();
        }
    }
}

只有本站会员才能查看附件,请 登录


程序代码:

Module Module1
    Public Class Student
        Public Property First
        Public Property Last
        Public Property ID

    End Class
    Sub Main()
        Dim students As List(Of Student) = New List(Of Student) From
            {
                New Student With {.First = "Svetlana", .Last = "Omelchenko", .ID = 111},
                New Student With {.First = "Claire", .Last = "O'Donnell", .ID = 112},
                New Student With {.First = "Sven", .Last = "Mortensen", .ID = 113},
                New Student With {.First = "Cesar", .Last = "Garcia", .ID = 114},
                New Student With {.First = "Debra", .Last = "Garcia", .ID = 115}
            }
        Dim sortedGroups =
            From student In students
            Order By student.Last, student.First
            Group student By student.Last(0) Into newGroup
            Order By newGroup.Key
            Select newGroup

        Console.ReadKey()
    End Sub

End Module


以上一个是C#.NET的写法,一个是的写法,同样的写法,在C#.NET上是正常的,为什么会错呢,请问要怎么改才可以

[此贴子已经被作者于2018-9-19 11:38编辑过]

0 回复
1