返回LINQ的单柱 [英] Return single column with Linq

查看:149
本文介绍了返回LINQ的单柱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 public string GetNameBySSN(string SSN)
 {
    var results = from c in Clients
                  where c.ClientSSN.Equals(IRRCNumber)
                  select c.FirstName;
    //return results.ToString();
 }



我要回的LINQ一个单独列的值,并不能确定是否有这样做一个快速简便的回报。我的评论,我知道没有返回值代码段,如果枚举通过收集我能得到的价值,但不知道是否有更好的方式在周围。

I want to return a single column value with Linq and not sure if there is way to do a quick easy return. I commented section of code that I know does not return the value and if enumerate through collection I can get the value but wondering if a better way was around.

我不明白,LINQ的基础被设置,它没有前期办法知道
结果设置了单个成员。

I do understand that Linq is Set based and that it has no upfront means know that the result is set with a single member.

推荐答案

results.FirstOrDefault();

这方法不会抛出异常,仅供参考。凡为@Mehrdad会。

This way will not throw an exception, FYI. Where as @Mehrdad will.

这篇关于返回LINQ的单柱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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