我正试图找到与LINQ的交叉点.
样品:
List<int> int1 = new List<int>() { 1,2 };
List<int> int2 = new List<int>();
List<int> int3 = new List<int>() { 1 };
List<int> int4 = new List<int>() { 1, 2 };
List<int> int5 = new List<int>() { 1 };
Run Code Online (Sandbox Code Playgroud)
想要返回:1,因为它存在于所有列表中..如果我运行:
var intResult= int1
.Intersect(int2)
.Intersect(int3)
.Intersect(int4)
.Intersect(int5).ToList();
Run Code Online (Sandbox Code Playgroud)
它返回什么,因为1显然不在int2列表中.无论一个列表是否为空,如何使其工作?
使用上面的例子或:
List<int> int1 = new List<int>() { 1,2 };
List<int> int2 = new List<int>();
List<int> int3 = new List<int>();
List<int> int4 = new List<int>();
List<int> int5 = new List<int>();
Run Code Online (Sandbox Code Playgroud)
在这种情况下如何返回1和2 ..如果列表已填充,我不知道提前...
我写了一个类,它有一些从unity容器中解析出来的依赖项.
从我的主类我创建一个新对象
MyObject myObject = new MyObject();
Run Code Online (Sandbox Code Playgroud)
我用我的Unity容器注册它
UContainer.RegisterInstance<MyObject>(myObject, new ExternallyControlledLifetimeManager());
Run Code Online (Sandbox Code Playgroud)
我创建了需要它作为依赖的类型
ConsumerObject consumer = new ConsumerObject();
Run Code Online (Sandbox Code Playgroud)
消费者看起来像这样:
public class ConsumerObject
{
public ConsumberObject()
{
theObject = (MyObject)UContainer.Resolve(typeof(MyObject));
}
}
Run Code Online (Sandbox Code Playgroud)
这引发了一个异常:
依赖项的解析失败,type ="MyObject",name ="".异常消息是:当前构建操作(构建密钥Build Key [MyObject,null])失败:尝试调用构造函数MyObject(IPreferenceStorageProvider pp)时无法解析参数pp.(策略类型BuildPlanStrategy,索引3)
为什么我的解决方案会尝试在该类型上调用另一个contsructor?我已经创建了它并注册了实例..我也试过它:theObject = UContainer.Resolve<MyObject>(); 似乎没有任何区别..
谢谢