在linq中选择vs选择新 [英] Select vs Select new in linq

查看:51
本文介绍了在linq中选择vs选择新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

b/w选择并在linq中选择new有什么区别.

What's the difference b/w select and select new in linq.

var SelectNew = from L1 in liStudent select new { L1.Name, L1.ID };

var SelectNew2 = from L2 in liStudent select L2;

推荐答案

您的第一个 SelectNew 返回的枚举匿名类型具有两个属性,分别是 Name ID ,而 SelectNew2 返回一个可枚举的 iiStudent 实体.需要返回实体/模型中可用数据的子集时,将使用第一个实例.

Your first one, SelectNew is returning an enumerable of anonymous types with two properties, Name and ID, whereas SelectNew2 is returning an enumerable of iiStudent entities. You'd use the first instance when you need to return a subset of the data available in the entity/model.

这篇关于在linq中选择vs选择新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆