积极答复者
晕了?!

问题
-
void Proxy_SearchSectionSCompleted(object sender, EMS.SLCore.SVC.SearchSectionSCompletedEventArgs e) {
var offices = from office in (ObservableCollection<EMS.SLCore.SVC.Office>)e.UserState
select new EMS.SLCore.TreeViewItemData<EMS.SLCore.SVC.Office>(office, null);
foreach (var office in offices) {
var rs = this.SetSectionTree(null, e.Result.Where(s=>s.OfficeCode==office.InnerEntity.Code));
if (office.InnerEntity.Code == "GZ") {
var ss = rs.Where(s => s.InnerEntity.OID == 10).FirstOrDefault();
var t = (from section in e.Result where section.UpId == 10 select new EMS.SLCore.TreeViewItemData<EMS.SLCore.SVC.Section>(section, null));
ss.Children = t;
MessageBox.Show(ss.Children == null ? "null" : ss.Children.Count<EMS.SLCore.TreeViewItemData<EMS.SLCore.SVC.Section>>().ToString());
this.show(rs.Where(s => s.InnerEntity.OID == 10));
}}
}
void show(IEnumerable<EMS.SLCore.TreeViewItemData<EMS.SLCore.SVC.Section>> rs) {
var ss = rs.Where(s => s.InnerEntity.OID == 10).FirstOrDefault();MessageBox.Show(ss.Children == null ? "null" : ss.Children.Count<EMS.SLCore.TreeViewItemData<EMS.SLCore.SVC.Section>>().ToString());
}
上面show方法中的那句代码就是从上面copy下来的,可是messagebox显示的就是不一样,上面很正常显示,显示"1",而下面则是"null"?这是为什么啊??搞了一天了,也没找到原因2009年9月7日 9:02
答案
-
只有一个可能了
你用了where这个操作了 它是延迟操作符
你确实引用了同一个对象 不过没有存储对象里面 ss不是rs对象了 是IEnumerable序列化对象- 已标记为答案 Allen Chen - MSFT 2009年9月14日 9:39
2009年9月8日 8:22
全部回复
-
void Test() {
var ss = rs.Where(s => s.InnerEntity.OID == 10).FirstOrDefault();
var t = (from section in e.Result where section.UpId == 10 select new EMS.SLCore.TreeViewItemData<EMS.SLCore.SVC.Section>(section, null));
ss.Children = t;
MessageBox.Show(ss.Children == null ? "null" : "Y :" + ss.InnerEntity.OID.ToString());
this.show(rs);
//this.show(rs.Where(s => s.InnerEntity.OID == 10));
}void show(IEnumerable<EMS.SLCore.TreeViewItemData<EMS.SLCore.SVC.Section>> rs) {
var ss = rs.Where(s => s.InnerEntity.OID == 10).FirstOrDefault();MessageBox.Show(ss.Children == null ? "null" : "N :" + ss.InnerEntity.OID.ToString());
}
ss.Children = t;肯定是有值的,因为在Test方法中,messagebox提示为"Y :1",有一个chidlren.
但是在show方法中,messagebox显示就是"null"
若在show方法中,把ss.children改为 ss,也就是只检查ss,是有值的
2009年9月8日 1:42 -
只有一个可能了
你用了where这个操作了 它是延迟操作符
你确实引用了同一个对象 不过没有存储对象里面 ss不是rs对象了 是IEnumerable序列化对象- 已标记为答案 Allen Chen - MSFT 2009年9月14日 9:39
2009年9月8日 8:22