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