开发者

Taking object without empty properties in Linq

I want to take pa but empty MG props.

Parent pa = new Parent()
               {
                   MC = new Child[]
                            {
                                new Child() {M1 = 1},
                                new Child() {M1 = 2},
                                new Child() {M1 = 3},
                            },
                   MG = new GrandChild[]
                            {
                                new GrandChild() {M2 = "1"},
                                new GrandChild() {M2 = ""},
                                new GrandChild() {M2 = ""},
                                new GrandChild() {M2 = "4"},
            开发者_运维技巧                },
                   MP = "just string prop",
               };

I know this is not true but wanna take my object like this way:

var vv = pa.MG.Where(_p=>_p.M2!="").Select(_k=>_k.**parent**) 


pa.MG = pa.MG.Where(gc => gc.M2 != "").ToArray();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜