C
C#12mo 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
Angius12mo ago
If a method — void or not — is too long, you can split it into more methods
Ewan
EwanOP12mo 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
Angius12mo 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
EwanOP12mo ago
GOT IT got it working thank you!
Want results from more Discord servers?
Add your server