❔ I need to make sure I understand and doing this correctly
I'm learning coding in class and this video explain classes and objects. I tried my best to follow what the instruction want while making sure I understand everything. I only got one error which I think I know where I messed up but I want to make sure everything else is correct.
17 Replies
there is not enough code i guess
also please paste text, images are not good
$code
Posting Code Snippets
To post a code snippet type the following:
```cs
// code here
```
Notes:
- Get an example by typing
$codegif
in the chat.
- Change the language by replacing cs
with the language of your choice (for example sql
or cpp
).
- If your code is too long, you can post it to https://paste.mod.gg/ and share the link.in the first image technically there isn't a closing }, although it could be outside
Got it.... Also what do you mean?
Oh
Yeah, it's outside it
@mrw419 You need to override ToString() method in Fruits class
What do you mean?
well probably first you need to correct the errors
why are errors not underlined
in
ToString
you have "fruit 1: " + Apple;
which is not a call nor an assignment, so it's a mistakei thought that was error, but it can work like this
also works this way too
@mrw419 So, every class in C# is sub-class of Object class. object have some methods inside it, like ToString. what inheritance means, everything not private from based class u also have in sub-class. like on thing i painted, so, that means in your Fruits class u have ToString Method (this method is virtual, that means it can be overridden), so, that ToString Method works different way in different environment. as i get, all u need to do, thats override this method in your Fruits class.
so that will be behavior of instance of Fruits class when it used like string.
i hope i explained it correctly and that was main problem here
and also here, i think we need to call constructor which have 0 arguments
like
or
I'll definitely need to overlook this when I get back to school. Since at this moment I'm out eating.
Some of those I never heard of yet such as override, internal class, {get; }
class Furits = internal class Fruits, almost everything have access modifiers, for classes by default is internal
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.