i want to get a reference from a list of objects on an object ,
so the reference i want object type
i will explain in the following example
i have a method like
method (ref Foo foo)
{
//
}
and i have a list of Foo
List<Foo> listFoo;
and i want to call this
method(ref listFoo[i])
so this return a reference of a listfoo and i want the reference of the foo number i in the list
thanks
If you mean the direct array reference; you cannot obtain that via a list. Not least, this is because the list is free to reassign the underlying array at any point – rendering your reference confusing at best.
If it was an array, the you could use the
method(ref arr[index])approach you mention; but only with arrays.Note: this trick is only useful in two scenarios:
structin-situ, without causing it to be copiedFor most purposes, passing the object reference is fine, i.e.