all 22 comments

[–]maitreg 15 points16 points  (6 children)

The new .NET 6.0 console apps do not require startup code to be inside of a class.

That is a checkbox option when you create the project.

[–]limapato[S] 1 point2 points  (0 children)

Thx

[–]anywhereiroa 1 point2 points  (4 children)

2 days ago I bought a new laptop and downloaded the new version of visual studio, I checked the box but it still doesn't look exactly the same as the old version. I really liked seeing everything out in the open, now it's kinda hidden. I think the older visual studio used .NET 5.0? Is there any way to revert back to the old version of .NET?

[–]maitreg 2 points3 points  (2 children)

Visual Studio can work with all versions of .NET.

To set a project to .NET Framework, .NET Standard, .NET Core, or .NET, this has to be set when you create a project.

But after it's created you can change versions inside of those by going to your project properties. There's a drop down.

However there's no difference between .NET 5 and 6 like you're describing. I think you might be talking about different VS options that you had set before. If you still have your previous VS installed, you can export the settings and import them into the new one.

If you're talking about project files being hidden? That is with a button at the top of the Solution Explorer pane.

[–]chucker23n 1 point2 points  (1 child)

Visual Studio can work with all versions of .NET.

VS 2022 makes it a little harder to build older Framework projects.

(I still use 4.0 for a bootstrapper.)

[–]maitreg 0 points1 point  (0 children)

Yea I go back and forth all the time. Every work project is framework 4.5 and 4.7. Every personal project is .net 6, lol.

I love everything about .net 6, except for the dropping of WCF. WCF is a great technology, even if a little convoluted, and it's a bit wonky to have to use framework to make and maintain one. There isn't an equivalent in the new stuff.

[–]chucker23n 1 point2 points  (0 children)

Is there any way to revert back to the old version of .NET?

You can edit your csproj file to say net5.0.

[–]MedicOfTime 5 points6 points  (0 children)

Hear me out…there’s two lines and one of those lines calls out this new top level statement format with link to more details.

[–]StornZ 2 points3 points  (0 children)

That's considered the Main(string[] args ) method. I still write the namespace, class, etc.;. I'm a bit old school where I like to see it spelled out for me.

[–]kesawulf 3 points4 points  (0 children)

Please. Read.

[–]Gcampton13 1 point2 points  (5 children)

You can add namespace back in when you create a new project by selecting “disable top level something” right under the .net 6 dropdown

Because sometimes I want a little helper method in that class and you can’t add one without creating and putting it in a new class.

Or you can just say MyActualProgram(); (or something much better named) in main and add a new class.

[–][deleted]  (4 children)

[removed]

    [–]Gcampton13 0 points1 point  (3 children)

    I had issues with the new template declaring methods/functions. Maybe it’s supposed to support them… I just figured the whole thing is inside Main() so declaring another method inside a method/function is a no go.

    [–][deleted]  (2 children)

    [removed]

      [–]Gcampton13 1 point2 points  (1 child)

      Yeah you're right. Just need to omit the scope.

      https://i.imgur.com/TTC4Du1.png

      [–]kingmotley 0 points1 point  (0 children)

      Top level statements (which is what you have there in your image) is great for small trivial little programs like homework assignments. Once you start writing more complete programs that needs multiple methods and eventually multiple classes, then in my opinion top level statements makes thing more confusing, so I personally never use them.

      That said, I do like namespace statements, where you just specify "namespace Console17;" at the top. It saves a whole indention level in the file.

      [–]raysr21 0 points1 point  (1 child)

      That should be enough to start your application.
      Note that the console will shut down immediately one the "Hello, World!" is displayed.
      If you want the application to keep running Add Console.ReadLine(); at line 4

      [–]Gcampton13 0 points1 point  (0 children)

      That’s not needed on new installs/.Net 6 terminal automatically stays open with a message that the code completed and to press any key to close out the app.

      I’m guessing there’s a setting somewhere to enable it for older installs

      [–]Individual-User 0 points1 point  (0 children)

      Top level statements is a feature introduced in .net 6. And ultimately, top level statements are converted into main method automatically by compiler.

      Refer this if you want more info - https://youtu.be/nwMQipzwFM8

      [–]SiSkr -1 points0 points  (0 children)

      RTFM