Categories > Coding > C# >

[TUTORIAL] How to write GOOD c# for dumb idiot stinky poopyheads

SeizureSalad

i love femboys

Posts: 1159

Threads: 79

Joined: Mar, 2021

Reputation: 40

Posted

Hello people of wearedevs i am going to teech how not to be poopy bad at c# and write good code :thumbsup:

 

Step 1. Dispose stuff

 

You should be disposing anything that you can. Such as WebClients like this

 

 

WebClient bruh = new WebClient();
// do whatever
bruh.Dispose();

OR

using WebClient bruh = new WebClient();
//no dispose

OR

using (WebClient bruh = new WebClient())
{
    //do whtaever
}

 

Using the using keyword you don't have to dispose. I personally think the second option is the best as it isn't scoped like the third one.

 

Step 2. Don't use WebClient

 

Reject WebClient (deprecated ew) return to HttpClient

 

Step 3. don't declare stupid variables

 

  • name your variables actually well isntead of soemthing like "AAAVARIABLEHALehfuafahlEHUAHO" or "var1"
  • don't declare 7 trillion varibles you don't need them when it can be condensed into a single line
string bruh = "e"
Console.WriteLine(bruh);
//BAD BAD BAD BAD BAD BAD BAD


//DO THIS
Console.WriteLine("e");

 

Step 4. Less line != good

 

While it is important to have neat code and not have too many lines too LITTLE lines can also be bad.

 

if (true) { Console.WriteLine("true"); } //bad

if (true)
    Console.WriteLine("true"); //good

if (true) Console.WriteLine("true"); //also good

if (true) 
{
    Console.WriteLine("true"); //Not great but better than first one
}

Step 5. tips and tricks

 

just some tips

 

 

if (FunctionThatReturnsBool() == true) 
{
    //Although this might be readable as this reads in english as "if function that returns bool is true" this is bad and redundant.
}

if (FunctionThatReturnsBool()) 
{
    //Good
}

/***********************************************************/

this.Whatever; //bad

Whatever; //good

 

Using the this keyword is gonna be useless and redundant 98.7% of the time but does have some uses but for the time being just don't use it

  • 1

"Questionable intellegence, but I like the mystery" - CubeFaces

https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png

Posts: 0

Threads: 0

Joined: ?

Reputation:

Replied

  • 0

SeizureSalad

i love femboys

Posts: 1159

Threads: 79

Joined: Mar, 2021

Reputation: 40

Replied

@63568 yeah really

  • 0

"Questionable intellegence, but I like the mystery" - CubeFaces

https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png

Posts: 381

Threads: 42

Joined: Feb, 2021

Reputation: 9

Replied

yes i dispose i wonder why no work 🤡

Form1 f = new Form1();
f.Show();
f.Dispose();
  • 0

https://media.discordapp.net/attachments/994643402949926956/1004560140252495960/uqJXQIda.gif

Read me.

Discord: Ad#1085; Don't hesitate to DM me if you need help/anything.

RiceUsesArchBtw

rice cracker

vip

Posts: 465

Threads: 19

Joined: Aug, 2021

Reputation: 39

Replied

instead of making a new webclient every time u request something u can just make a singleton and use it for tje whole project

  • 0

https://cdn.discordapp.com/attachments/1023423265160560745/1132948683747500092/Frame_12x.png

SeizureSalad

i love femboys

Posts: 1159

Threads: 79

Joined: Mar, 2021

Reputation: 40

Replied

@AlexSyndrome stfu smh I hope people aren't that stupid

  • 0

"Questionable intellegence, but I like the mystery" - CubeFaces

https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png

Posts: 17

Threads: 2

Joined: Jun, 2022

Reputation: 11

Replied

geniuenly good advice

  • 0

~iskrer

https://cdn.discordapp.com/attachments/1001178171510624439/1001614646282829934/unknown.png

Posts: 2014

Threads: 198

Joined: Apr, 2021

Reputation: 16

Replied

why the big font tho

  • 0

Random quote here...

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )