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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
cant i create a variable for all methods?
Unknown User
Unknown User3y 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
realivanjxツ
realivanjxツ3y ago
readonly?
realivanjxツ
realivanjxツ3y ago
well, readonly
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
doesnt matter t.b.h.
realivanjxツ
realivanjxツ3y ago
readonly string xxxx
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
aight gimme a sec.. doesnt work haha
realivanjxツ
realivanjxツ3y ago
oh you must be outside the function to use readonly
realivanjxツ
realivanjxツ3y ago
it is inside a main function. it is just invisible
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
ohh.. how do i fix that then? 😄
realivanjxツ
realivanjxツ3y ago
use the old boilerplate code
class Program
{
static void Main(string[] args)
{
}
}
class Program
{
static void Main(string[] args)
{
}
}
realivanjxツ
realivanjxツ3y ago
then u can use static readonly xxx
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
aight.. thanks 😄
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
cant i also access the string from anothger .cs?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
that confused me a little 😄
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
so what is a const then?
realivanjxツ
realivanjxツ3y ago
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
realivanjxツ
realivanjxツ3y ago
public readonly string
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
realivanjxツ
realivanjxツ3y ago
statics are PITA
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
still errors xD ohh nvm forgot static it does work :3 tyty ❤️
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
im lost with these shit haha
Thinker
Thinker3y ago
You can't use var in fields
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
what would be the fix then without a .tostring?
Thinker
Thinker3y ago
Replace var with string Fields need to have an explicit type
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
what do you mean by fields?
Thinker
Thinker3y ago
public static readonly string curDir is a field A field is a "variable" inside a class
Thinker
Thinker3y ago
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
Thinker
Thinker3y ago
catsip
₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭
thanks mate 🙂
Thinker
Thinker3y ago
np
Want results from more Discord servers?
Add your server