I have this code :
CreaPager(m_oPacchettiEnum, 1, 10);
private void CreaPager(IEnumerable enPass, int limiteUp, int limiteDown)
{
enPass= enPass.Skip(limiteDown).Take(limiteUp);
}
and I’d like, when I edit enPass, reflect the edit to m_oPacchettiEnum, without have a return IEnumerable<T> function.
So, edit directly m_oPacchettiEnum trought the function. I use to do it on C, don’t know if is possible on C# (but I think so).
I read somethings about using out, but seems that it doesnt work :
CreaPager(out m_oPacchettiEnum, 1, 10);
private void CreaPager(out IEnumerable enPass, int limiteUp, int limiteDown)
{
enPass= enPass.Skip(limiteDown).Take(limiteUp);
}
outdoesn’t work here because you can’t use anoutparameter in the method until it’s been assigned. Since your assignment usesenum(which you should rename) as part of the right-hand-side, it’s not allowed. Switchingouttorefwill make things work.However. As I mentioned in my answer to your previous (now deleted) question, please don’t do this. It is much more idiomatic when working with sequences to return a new
IEnumerable<T>:As well, you can make the method an extension method by preceding the first parameter with
this:Doing so would allow you to integrate your method into a LINQ-to-Objects call chain:
EDIT: Since you need to also return a
string, make that theoutparameter:You’d call the method like this:
outis fine here, since I’m assuming you don’t need to both use and assign the string. And if you do, then I would suggest you split it into two parameters anyway.