草庐IT

MyOtherObject

全部标签

c# - 在linq中使用之前如何检查null?

我有一个对象列表,其中包含另一个对象。ListmyClass=newList();我想像这样做一些linqmyClass.Where(x=>x.MyOtherObject.Name="Name").ToList();有时“MyOtherObject”为空。我该如何检查? 最佳答案 很简单,只需添加一个AND子句来检查它是否不为空:myClass.Where(x=>x.MyOtherObject!=null&&x.MyOtherObject.Name="Name").ToList(); 关

php - SimpleTest:如何断言抛出 PHP 错误?

如果我是正确的,SimpleTest将允许您断言抛出PHP错误。但是,根据文档,我不知道如何使用它。我想断言我传递给构造函数的对象是MyOtherObject的一个实例classObject{publicfunction__construct(MyOtherObject$object){//dosomethingwith$object}}//...andinmytestIhave...publicfunctiontestConstruct_ExpectsAnInstanceOfMyOtherObject(){$notAnObject='foobar';$object=newObject