C
C#7mo ago
Idok

What does code "new" means.

I would like to know what it means.
33 Replies
Moods
Moods7mo ago
Wdym? Do you have a code snippet to show? It depends on the context
Idok
Idok7mo ago
like, I have a hard time understanding what it does, I get the gist of it but I don't know
Moods
Moods7mo 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
Idok
Idok7mo ago
oh like variables example: string smth = new string[];
Moods
Moods7mo 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
Idok
Idok7mo ago
what does it do in the line of code liek like*
Moods
Moods7mo 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
Idok
Idok7mo ago
erhhhhhhhh I am stupid so it just like, makes it smth that's not the other thing
Moods
Moods7mo ago
Also it should be string[] smth = new string[insert a number here];
Idok
Idok7mo ago
ik I am tired
Moods
Moods7mo ago
Sorry
Idok
Idok7mo ago
not ur fault My choice to sleep deprive myself over this
Moods
Moods7mo ago
Okay okay, depending on whatever constructor is used after the keyword, it will return an instance of whatever type the constructor belongs to
Idok
Idok7mo ago
uhhh what is the contrustor? I forgot
Moods
Moods7mo ago
What comes after new, it’s a special function that’s used to initialize instance data
Idok
Idok7mo ago
ohhhhh so like how much it holds or smth ?
Moods
Moods7mo ago
The constructor you use determines what data the instance will hold initially So not how much, but what it holds
Idok
Idok7mo ago
oh so like think of it as a container?
Moods
Moods7mo ago
The instance is the container, the constructor determines what’s in the container initially And the new keyword creates the container
Idok
Idok7mo ago
ok so sorry for wasting your time but
Moods
Moods7mo ago
Nah don’t apologize I feel bad I am not explaining better I can send documents if they’d help Official Microsoft ones
Idok
Idok7mo 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
Moods7mo ago
Oh? I did not say that unless I am missing something
Idok
Idok7mo ago
figuratively
Moods
Moods7mo ago
Oh you’re saying I said a lot of stuff that isn’t easy to understand?
Idok
Idok7mo ago
yup
Moods
Moods7mo ago
Ah I see
Idok
Idok7mo 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
Moods7mo ago
Hmmm, you’d have to start from scratch to build a foundation to understand stuff like that
Idok
Idok7mo 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
Moods7mo 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
Idok
Idok7mo ago
Or maybe I'm just slow. 🥱😭
Want results from more Discord servers?
Add your server
More Posts
interacting with a local host api in blazorHello I need help getting my local host api to accept requests from my blazor app calls currently I EF Database is not seededHello! I have configured an Entity and the table needs to have an initial row. After creating the miWPF window doesn't render after openingI sometime experience this bug where when a window (whose mode is set to tool so that it only shows IndexOf being weird? (Advent of Code day1 semi-spoiler?)Okay I don't even know how to ask outside of "why?" Why does this not find the indexUser Control Eventhandler. How to get my control's components to inherit an Eventhandler.I have a User Control called `BoxButton` that I want to behave like a Button, I want my `PictureBox`Can someone explain to me what a bool is and how I can implement it in other data structures?Pretty much title, I'm trying to code a simple game in C# and my teacher suggested I use booleans tocannot set up a local SQL serveri have been trying to set up a sql server so i can get started on learning asp.net but have failed tClean architecture, how to register dbcontextSo in Presentation layer that's where API (controller) will be. Also that's an entry point for appliCustom 400 return type (application/fhir+xml)Currently working on an API that has to be FHIR compliant. FHIR has it's own conventions for dealingASP.NET Web API doesn't parse floating numbers with a '.'Hi everyone, I have a quick question about ASP.NET I am scratching my head over this for an hour now