✅ Need some help with classes
Not too sure how to correctly use attributes from a class in a class function
22 Replies
There are no attributes on the picture. Do you mean fields? Also, a class function is usually called a method
yeah thats what i meant
well methods are in effect just functions that take an extra hidden parameter
the
this
parameter
it's a reference to an object with your fields effectively
you could say this.F_name
in your function for clarity, if you were wondering how that worksalright
so what's your problem anyway?
it just keeps looping
ill enter an upper case first name and last name but it keeps asking for it
or a string where the first character is uppercase
what's 1 in Char.IsUpper?
the first character of the string
oh wait
indices are usually treated as offsets rather than positions
i see what ive done
so the first character is at offset 0
it should be 0 to check the first character
yeah
cheers
np
how do i get rid of the green underlines
it keeps saying that it could be null
check for null before assigning it
or make the fields nullable
thats just putting ? infront of them right
yes, after the type
string?
readline may return null
an empty string too
it works now so does it really matter?
it would throw an exception if you enter an empty string
or pipe from a file
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.
Closed!