有没有一种方法可以将数组转换为参数列表?
main(){
//"a" is an array or a list or some collection
myPrint(a.SomeMethod);
}
void myPrint(int a){
//Do Stuff to arguments
}
void myPrint(int a, int b){
//Do Stuff to arguments
}
void myPrint(int a, int b, int c){
//Do Stuff to arguments
}我想把"a“转换成一个参数/参数列表,这样它就会自动调用适当的函数。
发布于 2010-10-22 12:24:46
main(){
int[] a = {1,2,3};
MyPrint(a);
}
void MyPrint(int... x){
//Do Stuff to arguments (accessing them by its index)
}https://stackoverflow.com/questions/3993869
复制相似问题