我很抱歉问这个基本的问题,
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:如果有人认为这个问题是愚蠢的或出于某种原因不喜欢它。你可以在得到回答后删除这个问题,而不是标记或投票
尝试将查询更改为
string filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath).FirstOrDefault().ToString();
string filePath=componentContainer.Single(x=>x.ComponentName==fileName).FilePath;