string doesnt work?
i wanna make a variable for all methods.. so i dont have to write the variable over and over again.. how do i do that?
52 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
cant i create a variable for all methods?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
i dont know the const before the code actually xD
im pretty new tho..
would you like to tell me how i could such a variable? :3
readonly?
ye..
well, readonly
doesnt matter t.b.h.
readonly string xxxx
aight gimme a sec..
doesnt work haha
oh you must be outside the function to use readonly
well xD
it is inside a main function. it is just invisible
ohh.. how do i fix that then? 😄
use the old boilerplate code
tyty
then u can use
static readonly xxx
aight.. thanks 😄
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
cant i also access the string from anothger .cs?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
that confused me a little 😄
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
like that?
*
so what is a const then?
huh
const variable needs to be resolved at compile time. getting a return from a function is a runtime variable so cant be const
ahh.. i see
but why does this not work now xD
Variables.curDir
public readonly string
didnt fix it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
statics are PITA
still errors xD
ohh nvm
forgot static
it does work :3 tyty ❤️
xD
im lost with these shit haha
You can't use
var
in fieldswhat would be the fix then without a .tostring?
Replace
var
with string
Fields need to have an explicit typewhat do you mean by fields?
public static readonly string curDir
is a field
A field is a "variable" inside a classhmm.. okay..
Variable: local inside a method
Field: Variable inside a class, can be readonly and static
Property: A standard way to access private fields from outside a class, can be readonly and static
ahhh
i get it now..
:3
thanks mate 🙂
np