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?
![](https://utfs.io/f/3793e9fe-62ff-4361-b7d6-0ef35c618982-4pl4mu.png)
52 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
cant i create a variable for all methods?
Unknown User•2y 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
![](https://utfs.io/f/c30b9ed7-fae7-45ae-99e0-e063c819d34b-4pl4mu.png)
oh you must be outside the function to use readonly
![](https://utfs.io/f/6c988821-a2a5-4435-bc06-bde66e9e23d7-4pl4mu.png)
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•2y ago
Message Not Public
Sign In & Join Server To View
cant i also access the string from anothger .cs?
![](https://utfs.io/f/8984c866-571b-4656-8c21-a7724c775015-4pl4mu.png)
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
that confused me a little 😄
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
like that?
![](https://utfs.io/f/9a838ea9-373a-4402-9a1d-849747c596ae-4pl4mu.png)
*
![](https://utfs.io/f/53e4af9a-b4b9-4817-a74b-12f00012b954-4pl4mu.png)
so what is a const then?
huh
![](https://utfs.io/f/f56f558a-b0af-45ec-be96-6a85b7cc074e-4pl4mu.png)
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
![](https://utfs.io/f/1613640d-459a-45ce-9d63-56c9b2f62c35-4pl4mu.png)
didnt fix it
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
statics are PITA
![](https://utfs.io/f/b9916113-3194-4e34-83ef-27a368b8b5cb-4pl4mu.png)
still errors xD
ohh nvm
forgot static
it does work :3 tyty ❤️
xD
![](https://utfs.io/f/aa4fa899-b240-4566-a70d-f9b2ebe1c9fe-4pl4mu.png)
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
![catsip](https://cdn.discordapp.com/emojis/770049584738205696.png)
thanks mate 🙂
np