继上一个问题之后,我有以下代码:
var results =
from result in xml.Descendants(ns + "GetMetalQuoteResult")
select new
{
Type = result.Element(ns + "Type").Value,
Currency = result.Element(ns + "Currency").Value,
Date = result.Element(ns + "Date").Value,
Time = result.Element(ns + "Time").Value,
Rate = (decimal)result.Element(ns + "Rate"),
Bid = (decimal)result.Element(ns + "Bid"),
BidTime = result.Element(ns + "BidTime").Value,
ExpTime = result.Element(ns + "ExpTime").Value,
DisplayTime = result.Element(ns + "DisplayTime").Value,
DisplayDate = result.Element(ns + "DisplayDate").Value,
Ask = (decimal)result.Element(ns + "Ask"),
AskTime = result.Element(ns + "AskTime").Value,
};
如何访问这些元素?
例如,如果我想访问元素“Ask”的值,为什么我不能只使用下面的代码。
System.Diagnostics.WriteLine(results.Ask);
我是否在做一些愚蠢的错误,因为我收到以下错误
Error 2 'System.Collections.Generic.IEnumerable<AnonymousType#1>' does not contain a definition for 'Ask' and no extension method 'Ask' accepting a first argument of type 'System.Collections.Generic.IEnumerable<AnonymousType#1>' could be found (are you missing a using directive or an assembly reference?)