• 0

Help with Visual Studio 2005 > 2022


Question

My son asked if I could teach him some programming. I studied programming in university and it was mostly C#. I briefly did that after I graduated but then went into BI career and can't remember much about C# or VS.

I have all my material from school and thought my son can start with the Hello World console application like I did. I then downloaded VS2022 and created a new project but I guess a lot has changed.

Could someone explain this to me.

Back in the day when I created new console application I got this.

using System;
using System.Collections.Generic;
using System.Text;

namespace Hello
{
    class Program
    {
        static void Main(string[] args)
        {
            
        }
    }
}

 

Now with VS2022

I get this on new project.

Console.WriteLine("Hello world!");

 

Why no using, namespace, class etc?

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 1

Another good resource is W3Schools C# Tutorial, may be slightly out of date but should get him started.  

At the very core C# has evolved but a lot of the core language features are still the same as 1.0.  I personally dislike the Top-Level Statements feature but that's also coming from my background with C/C++.

Now what's jarring is the change from VB6 to VB.Net...

Link to comment
Share on other sites

  • 0
On 30/01/2023 at 21:08, Joni_78 said:

My son asked if I could teach him some programming. I studied programming in university and it was mostly C#. I briefly did that after I graduated but then went into BI career and can't remember much about C# or VS.

I had all my material from school and thought my son can start with the Hello World console application like I did. I then downloaded VS2022 and created a new project but I guess a lot has changed.

Could someone explain this to me.

Back in the day when I created new console application I got this.

Exactly, C# has changed (evolved?) a lot. You can read about this feature here. It is called Implicit Using

Link to comment
Share on other sites

  • 0

In addition to implicit using it's also top-level statements, you can check "Do not use top-level statements" when you create a project in VS2022 and the template will generate the more familiar namespace/class/main method declaration.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 0
On 30/01/2023 at 21:24, Joni_78 said:

Thanks. I guess i have a lot to catch up.

A lot of things have changed and a lot of new things have come on the scene. The three most important ones added in these years are  (IMHO) Generics, the Linq libraries and the async/await paradigm. Only these innovations have made a huge leap forward to the language and support frameworks. Then, of course, there is the switch from NET Framework to NET.Core and now just NET6.0/7.0 that allows to write programs also for Mac and Linux. The mobile world has entered in Visual Studio with Xamarin. OK, enough, there are thousands changes. It is not possible to make an exaustive list here.

Link to comment
Share on other sites

  • 0
On 30/01/2023 at 23:54, Matthew S. said:

Now what's jarring is the change from VB6 to VB.Net...

I couldn't (mentally) make the jump from VB6 to anything OOP, so I moved into testing instead. 

Link to comment
Share on other sites

  • 0
On 30/01/2023 at 18:54, Matthew S. said:

Another good resource is W3Schools C# Tutorial, may be slightly out of date but should get him started.  

At the very core C# has evolved but a lot of the core language features are still the same as 1.0.  I personally dislike the Top-Level Statements feature but that's also coming from my background with C/C++.

Now what's jarring is the change from VB6 to VB.Net...

That change made me give up on VB. I LOVED just banging projects out in 6, .net killed the fun of it for me. I moved onto webdev.

Link to comment
Share on other sites

  • 0

In Visual Studio 2022, the default template for a new console application has been simplified to provide a more streamlined and beginner-friendly experience. The new template removes some of the unnecessary code that was present in earlier versions, while still allowing you to write and run your program effectively.

The simplified template in VS2022 focuses on the essential part of a console application: printing "Hello world!" to the console output. The line of code you see,

Console.WriteLine("Hello world!");

, accomplishes this by using the Console class from the System namespace.

Although the previous template included a using statement, a namespace declaration, and a class definition, those are not required for a basic console application. In the simplified template, Visual Studio takes care of the necessary behind-the-scenes setup so that you can quickly start writing and executing your code.

If you wish to introduce your son to programming using the previous template structure you mentioned, you can still create a new console application project and manually add the code. Simply remove the default line Console.WriteLine("Hello world!"); and replace it with the code you provided:

using System;
using System.Collections.Generic;
using System.Text;

namespace Hello
{
    class Program
    {
        static void Main(string[] args)
        {
            
        }
    }
}

By doing this, you can replicate the structure you were familiar with and teach your son the traditional way of writing a console application. As per this Power BI training resource, it is very easy to get it done.

Remember that while the default template has changed, the core concepts and principles of programming remain the same. The change in the template is primarily aimed at making it more accessible and less overwhelming for beginners.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.