如何在一个int变量中存储LINQ的整数输出? [英] how to store an integer output of LINQ in an int variable?

查看:39
本文介绍了如何在一个int变量中存储LINQ的整数输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#在Linq中存储一个整数值,但是我不能.
这是我的代码

I am trying to store an integer value with Linq in C# but I can''t.
here is my code

var authentication = from s in account.AccountTs
  where (s.UserName == this.user && s.PassWord == this.pass)
  select s.ID;



s.ID是Sql表&的整数值我想将其存储在整数变量中,并在项目的其他部分中使用它,所以问题是:如何将其存储在整数变量中?
请帮帮我.



s.ID is an integer value of Sql table & I want to store it in an integer variable , and use it in other parts of my project , so the problem is: how to store it in a integer variable?
Help me please.

推荐答案

由于authentication是整数列表,因此您可以在该LINQ语句后添加以下行:

Since authentication is a list of integers you can add this line after that LINQ statement:

int id = authentication.FirstOrDefaukt();



希望对您有所帮助.



Hope it helps.


这篇关于如何在一个int变量中存储LINQ的整数输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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