Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

Can Visual Studio IDE console application used for creating basic C# object-oriented features ?

The "Introduction to classes" tutorial in following link assumes .NET Core SDK and Visual Studio Core are installed.

https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/index

Is Visual Studio IDE sufficient tool for coding, compiling, and running this tutorial?  File -  New  - Project  -  Visual C#  -   Console App (.NET Framework)
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Which version of VS?

from the web site:
This tutorial assumes you've finished the online introductory tutorials, and you've installed .NET Core SDK and Visual Studio Code.
I don't see why you wouldn't it be able to run that tutorial using VS 2017 or better.
Visual Studio is a far more powerful IDE than Visual Studio Code and apart from some clear distinctions (listed here: https://code.visualstudio.com/Docs/editor/whyvscode). Also, if you like you can use built-in Sandbox to do the entire exercise. Just click on Enter Focus Mode.

User generated image
Regards,
Chinmay.
Avatar of naseeam

ASKER

I'm using Visual Studio Pro 2017

I'm following "Introduction to classes" tutorial at the bottom of following link:

https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/index

.NET Core SDK and Visual Studio Code are not installed in my computer.  I want to create, compile, and run this tutorial in Visual Studio IDE.

I copied the code directly from tutorial.  Following is the code and compile errors:

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace classes
{
    class Program
    {
        static void Main(string[] args)
        {
            var account = new BankAccount("Amer", 1000);
            Console.WriteLine($"Account {account.Number} was created for {account.Owner} with {account.Balance} initial balance.");
        }
    }
}

Open in new window



BankAccount.cs
using System;

namespace classes
{
    public class BankAccount
    {
        public string Number { get; }
        public string Owner { get; set; }
        public decimal Balance { get;  }

        public void MakeDeposit(decimal amount, DateTime date, string note)
        {

        }
        public void MakeWithdrawal(decimal amount, DateTime date, string note)
        {

        }
   
    }

    /* constructor */
    public BankAccount(string name, decimal initialBalance)
    {
        this.Owner = name;
        this.Balance = initialBalance;
    }
}

Open in new window


Attached are compile errors.  Why doesn't it compile?
compile_errors.PNG
Hi Naseeam,

First things first, did you install .Net Core SDK as we discussed in other thread? If yes then you have to select appropriate framework when you create the project. After that things will be straightforward.

Regards,
Chinmay.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Once you have installed .Net Core, you will see the options shown below:User generated image
.Net Core is not required for that tutorial. It can be used but is not a requirement
Avatar of naseeam

ASKER

>> Just click on Enter Focus Mode
Instead, I created "Console App (.NET Framework)" application in Visual Studio IDE.  Why doesn't my tutorial program compile?

Regards,
have you moved your constructor inside the class?
What Eric  Said
a constructor has to be inside a class. move line 20 after 27

My Bad... I am way over my head in .Net Core nowadays as it is taking over the world. I did not notice you are doing a .Net Framework stuff. Sorry for the goof up.
Avatar of naseeam

ASKER

Is .Net Core required or not?

I don't have .Net Core installed.

I chose following?  
 User generated image
no .Net Core is not required for this specific tutorial. Yes you select the console app
if you want to demystify what .Net Core is, read https://en.wikipedia.org/wiki/.NET_Core
Avatar of naseeam

ASKER

Compilation is successful after moving constructor inside the class.

Expert found the root cause and provided working solution.