DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Coding Once, Thriving Everywhere: A Deep Dive Into .NET MAUI’s Cross-Platform Magic
  • Understanding the Good and the Bad of .NET Development Framework
  • Migration From .NET5 to .NET 6: Performance Benchmarks
  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide

Trending

  • Accelerating Debugging in Integration Testing: An Efficient Search-Based Workflow for Impact Localization
  • Orchestrating Microservices with Dapr: A Unified Approach
  • How Kubernetes Cluster Sizing Affects Performance and Cost Efficiency in Cloud Deployments
  • How to Merge HTML Documents in Java
  1. DZone
  2. Coding
  3. Languages
  4. How to Write Your First .NET Core 2.0 Application

How to Write Your First .NET Core 2.0 Application

In this post, we offer a short tutorial that will introduce you to the world of .NET Core development and create a simple app using C#.

By 
Dhananjay Kumar user avatar
Dhananjay Kumar
·
Nov. 14, 17 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
9.0K Views

Join the DZone community and get the full member experience.

Join For Free

Microsoft .NET Core is a cross-platform, open source software development framework that can be used to build applications for mobile, Windows, and the web. You can learn more about .NET Core here, but in this blog post, we'll walk you through how to create and publish a .NET Core application for Windows.

To work with .NET Core, first, you need to install it from here. While you can use any IDE to create a .NET Core application, I am going to use the Visual Studio 2017 Enterprise version. If you do not have Visual Studio installed, you may want to try the community edition, which can be found for free here. Once the environment is set, launch Visual Studio and create a new project by selecting File->New Project-> Visual C#-> .NET Core-> Console App. Besides C#, a .NET Core application can be used in other languages, like Visual Basic.

After successfully creating your project, you will see there is already template code in the Program.cs file which looks like listing 1, shown below:

Listing 1 
using System;
namespace helloworld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

This is the bare minimum code of a .NET Core application, which will print Hello World as an output. To build a project and run the application press F5. You will get the output as shown in the next image.

Now, let's modify the code to find the summation of two numbers. You can read the input from the keyword and add two numbers as shown in listing 2, below:

Listing 2
using System;

namespace helloworld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("My 1st .NET Core application");
            Console.WriteLine("Enter Number 1");
            double num1 = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Enter Number 2");
            double num2 = Convert.ToDouble(Console.ReadLine());
            double result = num1 + num2;
            Console.WriteLine(num1 + " + " + num2 + " = " + result);
            Console.WriteLine("Press any key to continue");
            Console.ReadKey(true);
        }
    }
}

To build this project and run the application press F5. You will get the output as shown in the next image:

So far, we have built a basic .NET Core application. And right from Visual Studio, we can also publish this .NET Core application. To do that, right click project in the solution explorer and click on Publish.

Here you can publish your app to Azure or another host. Right now, I am publishing it to a local folder, as you can see in the next image:

To publish, click on the publish button. In the Output window, you can see the publish success message as shown in the image below:

Now when you open the folder where you published your app, you will find various files. You need to run the .dll file to run the .NET Core application.

You can run your new .NET Core application using the command dotnetrun. Therefore, to run this application, execute command dotnetnet helloworld.dll as shown in the image below:

And as you can see, your new Windows application is published and running!

mobile app .NET

Published at DZone with permission of Dhananjay Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Coding Once, Thriving Everywhere: A Deep Dive Into .NET MAUI’s Cross-Platform Magic
  • Understanding the Good and the Bad of .NET Development Framework
  • Migration From .NET5 to .NET 6: Performance Benchmarks
  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!