void foo(Tuple<object> t)
{
}
void bar()
{
foo(Tuple.Create("hello"));
}
C#编译器返回
error CS1502: The best overloaded method match for 'foo(System.Tuple<object>)' has some invalid arguments
error CS1503: Argument 1: cannot convert from 'System.Tuple<string>' to 'System.Tuple<object>'
添加明确的类型Tuple.Create违背了它的目的。我如何说服编译器接受代码?
FWIW,我认为C++不存在这个问题:http://live.boost.org/doc/libs/1_33_1/libs/tuple/doc/tuple_users_guide.html#constructing_tuples
如果你不在乎被强类型化为什么不使用void foo(params object [] args)? – cordialgerm 2010-10-05 21:55:13