β ToString of a list of an object
I'm supposed to return a string of the teacher's name and all the students but we've never used a string like that nor have we made a list of an object and I've been stuck on this for 2 days and it frustrates me so much please help me
27 Replies
What are you stuck on?
Are you stuck on how to format the string?
idek
idk what I'm doing
What output do you want to get?
I want to return a string that looks like the third pic(with the students' info)
Alright, and I assume the 4th pic is what you tried, correct?
correct
Did you mean
s = s + ...
?ebfuowhgou reyes
yes
Or simply
s +=
right
but even with that
it doesn't work
like how do I even add things to a string
we never did it
Maybe because
curr
will never be null
You never set it to null
but it will get to null when it goes over all the students
Why would it?
because of curr = curr.getnext
it will get to the end eventually
What does
GetNext()
do?go to the pointer of it
does that make sense?
we were told it's just a list
Well, a linked list from what I see
But sure
So
GetNext()
returns null
when there are no more elements?right
In that case, all I can say is debug this code
Place a breakpoint, see what happens
Does
GetValue
return the student instance in that node?yes
and student has a ToString
so it should work I think
Yeah it should, do as zzzzzz said, debug the code.
how do I do that
Place a breakpoint and launch in debug mode
Then step through the code
$debug
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.