Pass multiple types of data arrays through method c# -
i'm creating method loops through each element of array, how can pass any type of data array used in method?
this have @ moment
public void loopthrough(array passed through) { for(int x = 0;arr.length;x++) }
as in if have int array, char array etc. how can pass them through without having separate method each data type? i.e loopthroughint, loopthroughchar
you use generics:
public void loopthrough<t>(t[] arr) { (int x = 0; x < arr.length; x++) { t t = arr[x]; } }
Comments
Post a Comment