Categories > Coding > C# >
[TUTORIAL] How to write GOOD c# for dumb idiot stinky poopyheads
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
"Questionable intellegence, but I like the mystery" - CubeFaces
https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png
"Questionable intellegence, but I like the mystery" - CubeFaces
https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png
Replied
yes i dispose i wonder why no work 🤡
Form1 f = new Form1();
f.Show();
f.Dispose();
Cancel
Post
https://media.discordapp.net/attachments/994643402949926956/1004560140252495960/uqJXQIda.gif
Discord: Ad#1085; Don't hesitate to DM me if you need help/anything.
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
Cancel
Post
https://cdn.discordapp.com/attachments/1023423265160560745/1132948683747500092/Frame_12x.png
"Questionable intellegence, but I like the mystery" - CubeFaces
https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png
Replied
geniuenly good advice
Cancel
Post
~iskrer
https://cdn.discordapp.com/attachments/1001178171510624439/1001614646282829934/unknown.png
Replied
why the big font tho
Cancel
Post
Random quote here...
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post