Extract method doesn't detect variable assignment
public void Test(object x)
{
LinkedList list = head;
while(list!=null && list.Value!=x)
{
list = list.Next;
}
}
if I extract the code in while loop, I will get something like
public void Test(object x)
{
LinkedList list = head;
MethodX(list,x);
}
private MethodX(LinkedList list, object x)
{
while(list!=null && list.Value!=x)
{
list = list.Next;
}
}
but it actually should be
public void Test(object x)
{
LinkedList list = head;
MethodX(list,x);
}
private MethodX(ref LinkedList list, object x)
{
while(list!=null && list.Value!=x)
{
list = list.Next;
}
}
Please sign in to leave a comment.
Hello Nat,
Try using list after the loop - R# is recognising that you don't do anything
with it!
Ronnie