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

当我尝试从下面运行代码时,我从上面得到错误。

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));  
4

1 回答 1

6

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

因此,编译器看到typeof(c)并知道typeof它只接受类型名称,因此正勇敢地尝试在某处、任何地方找到一个名为的类型c,但是,唉,它不能。所以,它告诉你“我找不到类型c”。

于 2013-07-04T13:29:59.620 回答