C
C#7mo ago
Ewan

✅ Ive made my void method too long and i wanna take some variables out of it, how can i do this?

?
4 Replies
Angius
Angius7mo ago
If a method — void or not — is too long, you can split it into more methods
Ewan
Ewan7mo ago
how does one do this? for some sections inside the void method, can i change them into methods and move the sections outside the void method and call them inside replacing the sections instead?
Angius
Angius7mo ago
public void Foo()
{
// code
// lots of code
// more code
}
public void Foo()
{
// code
// lots of code
// more code
}
can turn into
public void Foo()
{
var bar = Bar();
var baz = Baz(bar);
var fuz = Fuz(baz);
}

public T Bar()
{
// code
}

public U Baz(T bar)
{
// lots of code
}

public V Fuz(U baz)
{
// more code
}
public void Foo()
{
var bar = Bar();
var baz = Baz(bar);
var fuz = Fuz(baz);
}

public T Bar()
{
// code
}

public U Baz(T bar)
{
// lots of code
}

public V Fuz(U baz)
{
// more code
}
Ewan
Ewan7mo ago
GOT IT got it working thank you!