What does code "new" means.

I would like to know what it means.
33 Replies
Moods
Moods•2y ago
Wdym? Do you have a code snippet to show? It depends on the context
🪻Dead Boy Walking
like, I have a hard time understanding what it does, I get the gist of it but I don't know
Moods
Moods•2y 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
🪻Dead Boy Walking
oh like variables example: string smth = new string[];
Moods
Moods•2y 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
🪻Dead Boy Walking
what does it do in the line of code liek like*
Moods
Moods•2y 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
🪻Dead Boy Walking
erhhhhhhhh I am stupid so it just like, makes it smth that's not the other thing
Moods
Moods•2y ago
Also it should be string[] smth = new string[insert a number here];
🪻Dead Boy Walking
ik I am tired
Moods
Moods•2y ago
Sorry
🪻Dead Boy Walking
not ur fault My choice to sleep deprive myself over this
Moods
Moods•2y ago
Okay okay, depending on whatever constructor is used after the keyword, it will return an instance of whatever type the constructor belongs to
🪻Dead Boy Walking
uhhh what is the contrustor? I forgot
Moods
Moods•2y ago
What comes after new, it’s a special function that’s used to initialize instance data
🪻Dead Boy Walking
ohhhhh so like how much it holds or smth ?
Moods
Moods•2y ago
The constructor you use determines what data the instance will hold initially So not how much, but what it holds
🪻Dead Boy Walking
oh so like think of it as a container?
Moods
Moods•2y ago
The instance is the container, the constructor determines what’s in the container initially And the new keyword creates the container
🪻Dead Boy Walking
ok so sorry for wasting your time but
Moods
Moods•2y ago
Nah don’t apologize I feel bad I am not explaining better I can send documents if they’d help Official Microsoft ones
🪻Dead Boy Walking
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
Moods•2y ago
Oh? I did not say that unless I am missing something
🪻Dead Boy Walking
figuratively
Moods
Moods•2y ago
Oh you’re saying I said a lot of stuff that isn’t easy to understand?
🪻Dead Boy Walking
yup
Moods
Moods•2y ago
Ah I see
🪻Dead Boy Walking
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
Moods•2y ago
Hmmm, you’d have to start from scratch to build a foundation to understand stuff like that
🪻Dead Boy Walking
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
Moods•2y 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
🪻Dead Boy Walking
Or maybe I'm just slow. 🥱😭

Did you find this page helpful?