| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1908 人关注过本帖
标题:请教LINQ问题
只看楼主 加入收藏
ppppooiiuu
Rank: 1
等 级:新手上路
帖 子:158
专家分:0
注 册:2016-3-2
结帖率:46.15%
收藏
 问题点数:0 回复次数:0 
请教LINQ问题
图片附件: 游客没有浏览图片的权限,请 登录注册

程序代码:
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编辑过]

搜索更多相关主题的帖子: public Student First new With 
2018-09-19 11:36
快速回复:请教LINQ问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053870 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved