Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Linq中获取没有空属性的对象_Linq - Fatal编程技术网

在Linq中获取没有空属性的对象

在Linq中获取没有空属性的对象,linq,Linq,我想拿pa但是空MG道具 Parent pa = new Parent() { MC = new Child[] { new Child() {M1 = 1}, new Child() {M1 = 2},

我想拿
pa
但是空
MG
道具

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",
               };
我知道这不是真的,但我想这样对待我的目标:

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

什么是“_k.**parent**?如果您描述了您正在尝试做的事情,那么告诉您如何做会更容易。我想使用不带MG空元素的pa对象。是的…这是…为什么我不想更改属性的值:(
pa.MG = pa.MG.Where(gc => gc.M2 != "").ToArray();