Writing to text files
I've tried looking up what the static type means but it just isn't clear to me. Does someone have a good explanation of what that type indicates?
10 Replies
I did read it had something to do with instanciating objects, but it's not sticking
$static
In C#, static allows you to have members (classes, methods, etc) that are not tied to any particular instance and are therefore always, globally, accessible. When applying
static
members, take the following considerations:
β’ If there are to be multiple instances of a class, do not use static
β’ If you need to track state, do not use static
β’ If you are going to have multi threaded workflows, do not use static unless you're aware of the caveats
static
is best used for stateless methods, extension methods/classes and in areas where you understand the pros/cons. Read more here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/staticstatic
members are not attached to any specific instance. They're basically C#'s way of having free functions like what Python, JS, TS, and other languages allow, while still keeping the paradigm of "methods go into classes"
Non-static
members refer to each specific instance of a classaaaah that makes it much clearer!
Static = π
So if i had a class that was not static. I'd have to create an instance of that class (create an object) in order to utilize it's methods?
You can't use non-static members of a class without having an instance of that class
A static class cannot have non-static members in the first place
O_O
Does anyone by any chance know why my textfile.txt isn't being modified?
It's compiling and running without any problems. Altough no text is being changed
Have you used the debugger?
also, your
WritingTextToFile
method has a curious issue
these are not doing anything of value, just confusingYeah haha I kind of realized itβs redundant to use it
Iβll try the debugger today (;