Skip to content

Instantly share code, notes, and snippets.

@AramRafeq
Last active April 14, 2020 14:40
Show Gist options
  • Save AramRafeq/4bb1d6bf9b04392c39493fae66c73e2e to your computer and use it in GitHub Desktop.
Save AramRafeq/4bb1d6bf9b04392c39493fae66c73e2e to your computer and use it in GitHub Desktop.
if
if
if
if
if
end if
end if
end if
end if
end if
void DoSomething(string param1, string param2)
{
if (param1 != null)
{
if (param2 != null)
{
if (param1 == "Foo")
{
if (param2 == "Bar")
{
Console.WriteLine("Foo Bar!");
}
else
{
Console.WriteLine("Not Foo Bar !");
}
}
else
{
Console.WriteLine("Not Foo Bar !");
}
}
}
}
void DoSomethingBetter(string param1, string param2)
{
if (param1 == null)
return; // datwani return y bkay, yanish...
if (param2 == null)
throw new ArgumentNullException("param2"); // exception y throw bkay
if (param1 == "Foo" && param2 == "Bar")
Console.WriteLine("Foo Bar!");
else
Console.WriteLine("Not Foo Bar!");
}
void DoSomethingVeryShort(string param1, string param2)
{
if (param1 == null || param2 == null)
return;
if (param1 == "Foo" && param2 == "Bar")
Console.WriteLine("Foo Bar!");
else
Console.WriteLine("Not Foo Bar!");
}
void DoSomethingNoReturn(string param1, string param2)
{
bool everythingIsOkay = param1 != null && param2 != null;
if (everythingIsOkay)
{
if (param1 == "Foo" && param2 == "Bar")
Console.WriteLine("Foo Bar!");
else
Console.WriteLine("Not Foo Bar!");
}
}
void DoSomethingNoReturn2(string param1, string param2)
{
bool notNull = param1 != null && param2 != null;
bool notShort = param1.Length >= 3 && param2.Length >= 3;
bool everythingIsOkay = notNull && notShort;
if (everythingIsOkay)
{
if (param1 == "Foo" && param2 == "Bar")
Console.WriteLine("Foo Bar!");
else
Console.WriteLine("Not Foo Bar!");
}
}
void DoSomethingThirdWay(string param1, string param2)
{
if (param1 != null && param2 != null && param1.Length >= 3 && param2.Length >= 3)
{
if (param1 == "Foo" && param2 == "Bar")
Console.WriteLine("Foo Bar!");
else
Console.WriteLine("Not Foo Bar!");
}
}
void DoLoop()
{
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
for (int k = 0; k < 100; k++)
{
// do something
}
}
}
}
void DoLoop()
{
for (int i = 0; i < 100; i++)
{
FunctionA();
}
}
void FunctionA()
{
for (int j = 0; j < 100; j++)
{
FunctionB();
}
}
void FunctionB()
{
for (int k = 0; k < 100; k++)
{
// do something
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment