यह मेरा कार्य है:LINQ: IENumerable [बेनामी टाइप] कैसे घोषित करें?
private IEnumerable<string> SeachItem(int[] ItemIds)
{
using (var reader = File.OpenText(Application.StartupPath + @"\temp\A_A.tmp"))
{
var myLine = from line in ReadLines(reader)
where line.Length > 1
let id = int.Parse(line.Split('\t')[1])
where ItemIds.Contains(id)
let m = Regex.Match(line, @"^\d+\t(\d+)\t.+?\t(item\\[^\t]+\.ddj)")
where m.Success == true
select new { Text = line, ItemId = id, Path = m.Groups[2].Value };
return myLine;
}
}
मुझे संकलन त्रुटि मिलती है, क्योंकि "myLine" एक आईनेमरेबल नहीं है [स्ट्रिंग] और मुझे नहीं पता कि आईनेमरेबल [बेनामी]
कैसे लिखना है "निहित रूप से नहीं कनवर्ट करें 'System.Collections.Generic.IEnumerable [AnonymousType # 1]' to 'System.Collections.Generic.IEnumerable [string]' "
जब आप कहते हैं कि "नया {...}" चुनें, तो आपने एक अनाम टाइप किया है। यदि कोई स्ट्रिंग चुनें, तो यह काम करना चाहिए। –
नहीं, लेकिन आप IENumerable को वापस कर सकते हैं और CastByExample चाल का उपयोग कर सकते हैं। –