C
C#12mo ago
Myfavbop

What does code "new" means.

I would like to know what it means.
33 Replies
Moods
Moods12mo ago
Wdym? Do you have a code snippet to show? It depends on the context
Myfavbop
MyfavbopOP12mo ago
like, I have a hard time understanding what it does, I get the gist of it but I don't know
Moods
Moods12mo ago
Well I asked you to be more specific cus the keyword can be applied differently depending on the context, but I’ll assume you’re referring to the most common usage, which is the new operator Well, i don’t really know what else to say, but it’s used alongside a type’s constructor to create a new instance of this type
Myfavbop
MyfavbopOP12mo ago
oh like variables example: string smth = new string[];
Moods
Moods12mo ago
Something like
List<int> bar = new List<int>();
List<int> bar = new List<int>();
Here the new keyword is being used alongside the default constructor for List<int> to create a new instance of List<int> and to return a reference to it to the variable foo
Myfavbop
MyfavbopOP12mo ago
what does it do in the line of code liek like*
Moods
Moods12mo ago
It creates the instance of the type, what data the instance will have will depend on what constructor is used Which is usually after the new keyword
Myfavbop
MyfavbopOP12mo ago
erhhhhhhhh I am stupid so it just like, makes it smth that's not the other thing
Moods
Moods12mo ago
Also it should be string[] smth = new string[insert a number here];
Myfavbop
MyfavbopOP12mo ago
ik I am tired
Moods
Moods12mo ago
Sorry
Myfavbop
MyfavbopOP12mo ago
not ur fault My choice to sleep deprive myself over this
Moods
Moods12mo ago
Okay okay, depending on whatever constructor is used after the keyword, it will return an instance of whatever type the constructor belongs to
Myfavbop
MyfavbopOP12mo ago
uhhh what is the contrustor? I forgot
Moods
Moods12mo ago
What comes after new, it’s a special function that’s used to initialize instance data
Myfavbop
MyfavbopOP12mo ago
ohhhhh so like how much it holds or smth ?
Moods
Moods12mo ago
The constructor you use determines what data the instance will hold initially So not how much, but what it holds
Myfavbop
MyfavbopOP12mo ago
oh so like think of it as a container?
Moods
Moods12mo ago
The instance is the container, the constructor determines what’s in the container initially And the new keyword creates the container
Myfavbop
MyfavbopOP12mo ago
ok so sorry for wasting your time but
Moods
Moods12mo ago
Nah don’t apologize I feel bad I am not explaining better I can send documents if they’d help Official Microsoft ones
Myfavbop
MyfavbopOP12mo ago
No your explaining fine I just like, have harder time understanding bigger words like for a example, you said did The outrageous courageous lion decided to do a malicious deed to capture it's prey. I'd probably need to hear it again to understand
Moods
Moods12mo ago
Oh? I did not say that unless I am missing something
Myfavbop
MyfavbopOP12mo ago
figuratively
Moods
Moods12mo ago
Oh you’re saying I said a lot of stuff that isn’t easy to understand?
Myfavbop
MyfavbopOP12mo ago
yup
Moods
Moods12mo ago
Ah I see
Myfavbop
MyfavbopOP12mo ago
ok thx one more thing Like stuff like this: Represents the standard input, output, and error streams for console applications. This class cannot be inherited. I could not understand unless I built a personal meaning of it in my mind.
Moods
Moods12mo ago
Hmmm, you’d have to start from scratch to build a foundation to understand stuff like that
Myfavbop
MyfavbopOP12mo ago
that's why I make notes it's like a training book specifically for me to help ME understand the best way to understand it.
Moods
Moods12mo ago
I think that’s good then if it helps you understand better It’s easy to get lost though so don’t be too hard on yourself
Myfavbop
MyfavbopOP12mo ago
Or maybe I'm just slow. 🥱😭
Want results from more Discord servers?
Add your server