c# - Method which accepts both int[] and List<int> -


question: write single method declaration can accept both list<int> , int[]

my answer involved this:

void testmethod(object param) // object base class can accept both int[] , list<int>

but not intended answer, said so.

any ideas how method signature ?

you can use ilist<int> both, int[] , list<int> implement:

void testmethod(ilist<int> ints) 

on way can still use indexer or count property( yes, array has count property if cast ilist<t> or icollection<t>). it's greatest possible intersection between both types allows fast access, using for-loops or other supported methods.

note methods not supported if can called add, you'll notsuportedexception @ runtime("collection of fixed size") if use array.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -