1
我收到以下錯誤:由於你的currentProfile單人LINQ的 - 無法隱式轉換類型「System.Collections.Generic.IEnumerable
Profile currentProfile;
public Profile ActiveProfile()
{
currentProfile = new Profile();
return currentProfile =
(from profiles in xmlDoc.Element("PlayerPofiles").Element("Online").Elements("Player")
where (string)profiles.Element("Active") == "True"
select new Profile
{
Name = (string)profiles.Element("Name"),
Sex = (string)profiles.Element("Sex"),
Avatar = (string)profiles.Element("Avatar").Attribute("path") ?? "",
Created = (DateTime)profiles.Element("Created"),
Birthday = (string)profiles.Element("Birthday"),
Wins = (string)profiles.Element("Ratio").Element("Win"),
Losses = (string)profiles.Element("Ratio").Element("Loss"),
Abandoned = (string)profiles.Element("Ratio").Element("Abandoned")
});
}
感謝Dotnetstep ...修復它。 – Yecats 2011-12-25 03:36:48
你應該省略這一行'currentProfile = new Profile();',這是完全不必要的,該方法也應該返回'Profile' – 2011-12-25 04:15:02
謝謝@KrisIvanov - 我已經刪除了第一行。我很困惑,但爲什麼它應該返回Profile而不是currentProfile? – Yecats 2011-12-26 00:24:37