i was wandering if there is a way to pass an array to a function that is used on its members( kind of like how you pass the "this" parameter to object).
instead of this:
void public foo(A[] arr){}
void main(){
arr[i].foo(arr);
}
this:
void public foo(A[] arr){}
void main(){
arr[i].foo();
}
edit: arr is array of A, foo belongs to A sorry for bad explanation first question.
1 Answer 1
So... if I understand correctly. You want to call an item in the array, with a reference to the array.
But you don't want to pass that reference to the array?
I can only think of a working solution where you make a new class that encapsulates the array[] and create an add method, that upon adding handles the reference binding. (so passing a ref of itself to the added object). So that the items in the array hold a reference to the array.
or maybe you can do some nifty stuff using indexers:
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/indexers/
Hope this helps!
arr.foo()
notarr[i].foo()
.foreach(A a in arr)foo(a);
Or am I misunderstanding the question?void public foo(data_type var) { .... } void main() { foo(arr[i]) }