将 linq 查询的输出转换为字符串时出现问题

发布于 2024-11-01 22:57:04 字数 768 浏览 0 评论 0原文

我很抱歉问这个基本问题,

var filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath);

我想将输出转换为字符串。

我尝试了这些事情:

string filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath).ToString();

两次

 var filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath);
        string filePathInString = filePath.ToString();

我都收到错误:

Linq.Internals.UnoptimizedQuery<string>

请帮助我

我应该如何解决这个问题?

PS:如果有人认为这个问题很愚蠢或者出于某种原因不喜欢它。您可以在得到答案后删除此问题,而不是对其进行标记或否决

I'm sorry to ask this basic question,

var filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath);

I want to convert the output to string.

I tried these things:

string filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath).ToString();

and

 var filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath);
        string filePathInString = filePath.ToString();

both times i'm getting error:

Linq.Internals.UnoptimizedQuery<string>

Please help me out

How should i solve this problem ?

PS: If some one thinks this question is stupid or for some reason does not like it. U may delete this question after getting answered instead of flagging or down voting it

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薯片软お妹 2024-11-08 22:57:04

尝试将查询更改为

string filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath).FirstOrDefault().ToString();

Try changing the query to

string filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath).FirstOrDefault().ToString();
七度光 2024-11-08 22:57:04
string filePath=componentContainer.Single(x=>x.ComponentName==fileName).FilePath;
string filePath=componentContainer.Single(x=>x.ComponentName==fileName).FilePath;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文