C
C#15mo ago
mh4s

whats this, is this just console or .net console when creating a new project with visual studio 22?

No description
33 Replies
mh4s
mh4sOP15mo ago
yeah
Pobiega
Pobiega15mo ago
Thats the old default program template for console apps, yes Did you perhaps accidentally pick .net framework?
mh4s
mh4sOP15mo ago
is it the .net one or normal console app i created it using cmd like dotnet new console --use-program-main thats what we have been doing
Pobiega
Pobiega15mo ago
Ah on Yeah then its modern .net
mh4s
mh4sOP15mo ago
so is it good or no? im new to c#
Pobiega
Pobiega15mo ago
Yes
mh4s
mh4sOP15mo ago
No description
mh4s
mh4sOP15mo ago
what about when i create from this which one should i pick
Pobiega
Pobiega15mo ago
Top good, bottom bad
mh4s
mh4sOP15mo ago
can u explain why is that?
Pobiega
Pobiega15mo ago
.net framework is old and legacy It was discontinued in 2016
mh4s
mh4sOP15mo ago
then what did i create from my console the top one?
Pobiega
Pobiega15mo ago
Yws
mh4s
mh4sOP15mo ago
is it with top level statements?
Pobiega
Pobiega15mo ago
No, you explicitly opted for the program main instead
mh4s
mh4sOP15mo ago
No description
mh4s
mh4sOP15mo ago
what is this?
Pobiega
Pobiega15mo ago
That's what --use-program-main does Ignore NAOT as a beginner It's an advanced thing
mh4s
mh4sOP15mo ago
okay okay @Pobiega i have one more question though
mh4s
mh4sOP15mo ago
No description
mh4s
mh4sOP15mo ago
why do visual studio (left) and console (right) create a different thing inside? or just anyone who can answer, thanks
Pobiega
Pobiega15mo ago
It doesn't Those are the same
mh4s
mh4sOP15mo ago
i guess they work the same but there are some slight differences
Pobiega
Pobiega15mo ago
The left just has aN explicit access modifier
mh4s
mh4sOP15mo ago
can u talk more humanish?
Pobiega
Pobiega15mo ago
But the default access for classes is internal
mh4s
mh4sOP15mo ago
thats still too not humanish
Pobiega
Pobiega15mo ago
Google C# access modifiers Or take my word for it, it's the same
mh4s
mh4sOP15mo ago
so it doesnt matter that there is a slight difference @Pobiega
Dinosaure
Dinosaure15mo ago
The namespace is file-bound on the right, block-bound on the left. It doesn’t change the code, and removes one indentation layer. Plus, as stated by @Pobiega, your Program is explicitly set to internal on the left, while kept implicitly internal (by default) on the right. So both are the same code.
Pobiega
Pobiega15mo ago
Classes are internal by default, not private
Dinosaure
Dinosaure15mo ago
Thanks for the reminder, both are strictly equivalent.
Pobiega
Pobiega15mo ago
In a single-class project such as this, yes, but its still worth knowing. Private classes are extremely rare, while internal are quite common.

Did you find this page helpful?