2013-07-04 67 views
2
The type or namespace name 'c' could not be found (are you missing a using directive or an assembly reference?) 

当我尝试从下面运行代码时,我从上面找到了错误。带内部Lambda表达式的Lambda表达式

this.Calendar.Entries.Any<CalendarEntry>(c => c.Date.Date == date.Date && Filters.Any<Type>(f => typeof(c).IsInstanceOfType(f))); 

有谁知道为什么这不起作用?如果我可以得到它的工作?

谢谢。

编辑:

不过现在知道为什么,因为我最初写的这是行不通的,但是当我把它写这样它的工作原理:

Filters.Any<Type>(f => this.Calendar.Entries.Where<CalendarEntry>(c => c.Date.Date == date.Date).SingleOrDefault().GetType().IsInstanceOfType(f)); 

回答

6

typeof适用于类型名称。如果您需要运行时类型c,则必须使用Object.GetType并说c.GetType()

所以,编译器看到typeof(c),知道typeof只接受类型名称,因此试图英勇找到a type named c地方,任何地方,但,唉,它不能。所以,它告诉你“我找不到c”。

+0

谢谢。有用!!!我很傻,忘记了如何使用typeof :) –