(C#) why does Visual Studio say it's an object while GetType says it's a Func<object>?

后端 未结 3 1095
眼角桃花
眼角桃花 2021-01-03 14:29

C# newbie question here. The following code (taken from the book \"C# From Novice to Professional\" by Christian Gross, Apress) gives an error:

worksheet.Ad         


        
3条回答
  •  旧巷少年郎
    2021-01-03 15:02

    VS claims that both args in the method call above are of type object whereas the method accepts only Func. But the value of both worksheet elements is of type Func

    Yes, but the declared type is object. The compiler can't know that the actual runtime type will be Func, so an explicit cast is necessary.

    提交回复
    热议问题