C#
C#

help

Root Question Message

haakonsen
haakonsen12/8/2022
✅ Need some help with classes

Not too sure how to correctly use attributes from a class in a class function
AntonC
AntonC12/8/2022
There are no attributes on the picture. Do you mean fields? Also, a class function is usually called a method
haakonsen
haakonsen12/8/2022
yeah thats what i meant
AntonC
AntonC12/8/2022
well methods are in effect just functions that take an extra hidden parameter
AntonC
AntonC12/8/2022
the this parameter
AntonC
AntonC12/8/2022
it's a reference to an object with your fields effectively
AntonC
AntonC12/8/2022
you could say this.F_name in your function for clarity, if you were wondering how that works
haakonsen
haakonsen12/8/2022
alright
AntonC
AntonC12/8/2022
so what's your problem anyway?
haakonsen
haakonsen12/8/2022
it just keeps looping
haakonsen
haakonsen12/8/2022
ill enter an upper case first name and last name but it keeps asking for it
haakonsen
haakonsen12/8/2022
or a string where the first character is uppercase
AntonC
AntonC12/8/2022
what's 1 in Char.IsUpper?
haakonsen
haakonsen12/8/2022
the first character of the string
haakonsen
haakonsen12/8/2022
oh wait
AntonC
AntonC12/8/2022
indices are usually treated as offsets rather than positions
haakonsen
haakonsen12/8/2022
i see what ive done
AntonC
AntonC12/8/2022
so the first character is at offset 0
haakonsen
haakonsen12/8/2022
it should be 0 to check the first character
haakonsen
haakonsen12/8/2022
yeah
haakonsen
haakonsen12/8/2022
cheers
AntonC
AntonC12/8/2022
np
haakonsen
haakonsen12/8/2022
how do i get rid of the green underlines
haakonsen
haakonsen12/8/2022
it keeps saying that it could be null
AntonC
AntonC12/8/2022
check for null before assigning it
AntonC
AntonC12/8/2022
or make the fields nullable
haakonsen
haakonsen12/8/2022
thats just putting ? infront of them right
AntonC
AntonC12/8/2022
yes, after the type
AntonC
AntonC12/8/2022
string?
haakonsen
haakonsen12/8/2022
AntonC
AntonC12/8/2022
readline may return null
AntonC
AntonC12/8/2022
an empty string too
haakonsen
haakonsen12/8/2022
it works now so does it really matter?
AntonC
AntonC12/8/2022
it would throw an exception if you enter an empty string
AntonC
AntonC12/8/2022
or pipe from a file
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy