0% found this document useful (0 votes)
6 views25 pages

Introduction to .NET Development Basics

.NET is Microsoft's development platform for creating enterprise systems, featuring a Common Type System, Common Language Specification, and Common Language Runtime. It includes multiple platforms like .NET Framework, .NET Core, and the unified .NET, along with support for various programming languages such as C#, F#, and Visual Basic. The document also outlines how to create .NET applications using both the command line and Visual Studio, and explains the concept of top-level statements in C#.

Uploaded by

JDB1979
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views25 pages

Introduction to .NET Development Basics

.NET is Microsoft's development platform for creating enterprise systems, featuring a Common Type System, Common Language Specification, and Common Language Runtime. It includes multiple platforms like .NET Framework, .NET Core, and the unified .NET, along with support for various programming languages such as C#, F#, and Visual Basic. The document also outlines how to create .NET applications using both the command line and Visual Studio, and explains the concept of top-level statements in C#.

Uploaded by

JDB1979
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to .

NET
Contents

1. Overview of .NET
2. Creating a .NET app at the command line
3. Creating a .NET app by using Visual Studio
4. Understanding top-level statements

Demos folder:
Demos-02-IntroDotNet

2
1. Overview of .NET

◼ What is .NET?
◼ .NET platforms
◼ .NET programming languages
◼ Understanding Intermediate Language (IL)

3
What is .NET?

◼ .NET is Microsoft's strategic development platform for


developing enterprise systems for the modern era

◼ .NET provides:
• Common Type System (CTS), defines how data types work in .NET
• Common Language Specification (CLS), for language interop
• Common Language Runtime (CLR), manages objects at run time
• A large class library for common tasks (IO, data access, web, etc.)

4
.NET Platforms

◼ .NET Framework
• Available since 2002, only runs on Windows
• Suitable for desktop GUI apps (e.g. Windows Forms, WPF)
• Historically also used to create server apps (e.g. Web, WCF, REST)

◼ .NET Core
• Available since 2016, portable across Windows, Linux, Mac
• Mainly used for server apps (Web, REST)
• Offers a (quite large) subset of .NET Framework capabilities

◼ .NET
• Available since 2019, unifies .NET Framework and .NET Core
• This is what you should use today and going forward
5
.NET Programming Languages

◼ .NET offers several programming languages

• C#
◼ Very similar to C++ and Java

• F#
◼ Functional programming language

• Visual Basic
◼ An object-oriented evolution of VB6

• C++/CLI
◼ Has keywords that enable you to write C++ apps for .NET

6
Understanding Intermediate Language (IL)

◼ Each compiler emits the same bytecode format


• Intermediate Language (IL) bytecodes
• You can mix-and-match code written in any .NET language

[Link] [Link] [Link]

[Link] [Link] [Link]

IL bytecodes IL bytecodes IL bytecodes

7
2. Creating a .NET App at the Command Line

◼ Overview
◼ Creating a console app
◼ Reviewing the generated app
◼ Building and running the app

8
Overview

◼ You can create a .NET application at the command line


• Use [Link]
• This is the .NET CLI (Command Line Interface) tool

◼ Open a Developer Command Prompt for VS2022 window


and run the [Link]

9
Creating a Console App

◼ .NET CLI provides the following commands by default:


• new
• restore
• run
• build
• test
• publish
• pack

◼ To create a new console app:


• Create a suitably-named folder, e.g. DemoApp1
• Go to that folder and run the following command:
dotnet new console

10
Reviewing the Generated App

◼ The generated app contains simple C# entry-point code


// See [Link] for more information
[Link]("Hello, World!");

[Link]

◼ The generated app also contains a .csproj project file


<Project Sdk="[Link]">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>

[Link]

11
Building and Running the App

◼ Build and run the app as follows:


dotnet run

◼ This compiles the code into IL bytecode files


• See the bin folder

◼ The command then runs the application

12
3. Creating a .NET App by using Visual Studio

◼ Overview
◼ Creating a console app
◼ Reviewing the generated app
◼ Building and running the app

13
Overview

◼ Visual Studio is a single development environment for all


.NET languages
• Multiple project types
• Multiple .NET languages
• Multiple .NET versions
• Integrated debugging support
• Development web server for [Link] web apps
• Integrated access to additional library packages

◼ Let's create a new project in Visual Studio…

14
Creating a Console App (1 of 3)

◼ Select the Console App template, then click Next

15
Creating a Console App (2 of 3)

◼ Specify a project name and location, then click Next

16
Creating a Console App (3 of 3)

◼ Select the target framework, then click Create

17
Reviewing the Generated App (1 of 2)

◼ You can use the Solution Explorer window to view the


contents of your project

18
Reviewing the Generated App (2 of 2)

◼ The C# code is the same as when we used the CLI tool


// See [Link] for more information
[Link]("Hello, World!");

[Link]

◼ The .csproj file is also the same as before


• To see this file, right-click the project and click Edit Project File
<Project Sdk="[Link]">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>

[Link]

19
Building and Running the App

◼ To build and run the app:


• On the menu, select Debug | Start without Debugging
• Or press Ctrl+F5

◼ To build and debug the app:


• On the menu, select Debug | Start Debugging
• Or press F5

20
4. Understanding Top-Level Statements

◼ Using top-level statements


◼ Not using top-level statements
◼ Full program syntax

21
Using Top-Level Statements

◼ So far, our top-level program code looks like this:


// See [Link] for more information
[Link]("Hello, World!");

[Link]

◼ This simple syntax is called "top-level statements"


• Introduced in C# 9

22
Not Using Top-Level Statements

◼ It's also possible not to use top-level statements


• When you create the project…
• Select the option "Do not use top-level statements"

23
Full Program Syntax

◼ The top-level program code now looks like this:


namespace DemoApp3
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Hello, World!");
}
}
} [Link]

◼ Synopsis:
• Define a namespace and a Program class
• Implement a static Main() entry-point method
• Optionally declare an array of strings as input to Main()
• Optionally return an int from Main()

24
Any Questions?

25

You might also like