Skip to content

Commit 237de6c

Browse files
committed
Add file-based programs to get started
1 parent 56151df commit 237de6c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

docs/csharp/tour-of-csharp/overview.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Overview
33
description: New to C#? Learn the basics of the language. Start with this overview.
4-
ms.date: 03/17/2025
4+
ms.date: 06/20/2025
55
---
66

77
# A tour of the C# language
@@ -34,6 +34,22 @@ The `Program` class declared by the "Hello, World" program has a single member,
3434
> [!TIP]
3535
> The examples in this article give you a first look at C# code. Some samples might show elements of C# that you're not familiar with. When you're ready to learn C#, start with our [beginner tutorials](./tutorials/index.md), or dive into the links in each section. If you're experienced in [Java](./tips-for-java-developers.md), [JavaScript](./tips-for-javascript-developers.md), [TypeScript](./tips-for-javascript-developers.md), or [Python](./tips-for-python-developers.md), read our tips to help you find the information you need to quickly learn C#.
3636
37+
## File based programs
38+
39+
C# is a *compiled* language. In most C# programs, you use the [`dotnet build`](../../core/tools/dotnet-build.md) command to compile a group of source files into a binary package. Then, you use the [`dotnet run`](../../core/tools/dotnet-run.md) command to run the program. (You can simplify this process because `dotnet run` compiles the program before running it if necessary.) These tools support a rich language of configuration options and command line switches. The `dotnet` command line interpreter (CLI), which is included in the .NET SDK, provides many [tools](../../core/tools/index.md) to generate and modify these files.
40+
41+
Beginning with C# 14 and .NET 10, you can create *file based programs*, which simplifies building and running csharp programs. You use the `dotnet run` command to run a program contained in a single `*.cs` file. For example, you run the following snippet, when stored in the file `hello-world.cs`, by typing `dotnet run hello-world.cs`:
42+
43+
:::code language="csharp" source="./snippets/file-based-programs/hello-world.cs":::
44+
45+
The first line of the program contains the `#!` sequence for unix shells. On any unix system, if you set the *execute* (`+x`) permission on a C# file, you can run the C# file from the command line:
46+
47+
```bash
48+
./hello-world.cs
49+
```
50+
51+
The source for these programs must be a single file, but otherwise all C# syntax is valid. You can use file based programs for small command-line utilities, prototypes, or other experiments.
52+
3753
## Familiar C# features
3854

3955
C# is approachable for beginners yet offers advanced features for experienced developers writing specialized applications. You can be productive quickly. You can learn more specialized techniques as you need them for your applications.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/dotnet run
2+
Console.WriteLine("Hello, World!");

0 commit comments

Comments
 (0)