我有一个需要有条件地执行的方法的方法,像这样:在匿名方法/函数传递在C#中的参数
int MyMethod(Func<int> someFunction)
{
if (_someConditionIsTrue)
{
return someFunction;
}
return 0;
}
我希望能够在通过LINQ查询MyMethod as someFunction:
int i = MyMethod(_respository.Where(u => u.Id == 1).Select(u => u.OtherId));
我该怎么做?
卫生署!我几乎这样做了,但是我有'()= _repository'而不是'()=> _respository'。这工作完美,谢谢! – 2011-04-30 14:49:31
@Jerad Rose我很高兴我能帮忙:) – 2011-04-30 15:15:47