可以在LINQ方法中的Lambda中使用TryParse吗? [英] Can TryParse be used in a Lambda in a LINQ method?

查看:102
本文介绍了可以在LINQ方法中的Lambda中使用TryParse吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<由mod编辑>


有这个表达式...

展开 | 选择 | Wrap | 行号

解决方案

是的,有。您将使用多行lambda:

展开 | 选择 | Wrap | 行号


Gary的问题让我想到尝试一些疯狂的东西,它工作得很好:

展开 | 选择 | 换行 | 行号


谢谢你们。看来我是在正确的轨道上,我只是错过了花括号(现在明显的默认返回)。使用该参数,x是什么类型,或者只是var类型?是允许给它一个显式类型还是将它保留为var的约定,然后只是尝试将它放在你的lambda中?


另外,Linq令人困惑......

<edited by mod>

Having this expression...

Expand|Select|Wrap|Line Numbers

解决方案

Yes, there is. You''d use a multi-line lambda:

Expand|Select|Wrap|Line Numbers


Gary''s question led me to try something crazy, which was working quite good:

Expand|Select|Wrap|Line Numbers


Thanks guys. It seems I was on the right track, I was just missing the curly braces (and the now obvious default return). With that parameter, what type is x, or is it just that var type? Is it allowed to give it an explicit type or is the convention to leave it as var, then just try to cast it inside your lambda?

Also, Linq is confusing...


这篇关于可以在LINQ方法中的Lambda中使用TryParse吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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