开发者

Taking object without empty properties in Linq

开发者 https://www.devze.com 2023-01-09 06:55 出处:网络
I want to take pa but empty MG props. Parent pa = new Parent() { MC = new Child[] { new Child() {M1 = 1}, new Child() {M1 = 2},

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

精彩评论

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

关注公众号