开发者

problem with converting the output from linq query to string

开发者 https://www.devze.com 2023-02-27 07:59 出处:网络
I\'m sorry to ask this basic question, var filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath);

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 comp开发者_开发技巧1.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


Try changing the query to

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号