嗨,我有一個問題,香港專業教育學院在它被黑客攻擊了幾個小時我不斷收到錯誤修改LINQ輸出AnonymousType不能分配
屬性或索引「AnonymousType#1.XP」不能被分配到 - 它 是隻讀
在這裏a.XP
foreach (var a in comments)
{
a.XP = score.getLevel(a.XP);
}
出現的問題和評論指出,我從來沒有說什麼,我想不要e,我想用改進後的值score.getLevel(a.XP)替代a.XP。
下面是完整的代碼
protected void GetComments()
{
TimberManiacsDataContext db = new TimberManiacsDataContext();
Score score = new Score();
var comments = (from fComment in db.Comments
where fComment.PublishID == Convert.ToInt32(Request.QueryString["Article"])
orderby fComment.DateTime descending
select new
{
UserName = fComment.User.UserLogin.Username,
PostTime = fComment.DateTime,
UserImage = fComment.User.UserGeneralInfo.ProfilePicture,
Comment = fComment.Comment1,
UserID = fComment.UserID,
XP = fComment.User.CommunityScore
}).Take(10).ToList();
foreach (var a in comments)
{
a.XP = score.getLevel(a.XP);
}
Commentlist.DataSource = comments;
Commentlist.DataBind();
}
難道你不明白什麼部分錯誤消息的? – svick 2012-03-18 02:06:28
如何解決它,我想用新的和改進的值替代a.XP score.getLevel(a.XP) – 2012-03-18 02:08:16
另外,約定在C#中將您的方法命名爲「GetScore」,而不是' getScore'。類的公共表面區域應使用此版本的PascalCasing。 camelCasing被保留給私人會員,當地人等。 – 2012-03-18 02:15:13