Skip to content

Add file based program tutorial #47886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

@dotnetrepoman dotnetrepoman bot added this to the August 2025 milestone Aug 7, 2025
@BillWagner BillWagner marked this pull request as ready for review August 8, 2025 17:43
@BillWagner BillWagner requested a review from a team as a code owner August 8, 2025 17:43
@BillWagner BillWagner requested a review from adegeo August 8, 2025 17:43
Copy link
Contributor

@adegeo adegeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a lot of feedback on this one 😸 I think it's good feedback but please feel free to push back on whatever you think doesn't make sense. Let me know when you want another review.

@@ -0,0 +1,246 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment:

There are a lot of mixed "file based" and "file-based" references here that you should fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swept the other content I wrote for this feature as well. The correct product team term is "file-based app". I standardized on that everywhere.


> [!IMPORTANT]
>
> The version `2.0.0-beta6` was the latest version when this tutorial was last updated. If there's a newer version available, use the latest version to ensure you have the latest security packages.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note as the previous package tip here.

Comment on lines +202 to +205
Define the delay option and messages argument. In command-line applications, options typically begin with `--` (double dash) and can accept arguments. The `--delay` option accepts an integer argument that specifies the delay in milliseconds. The `messagesArgument` defines how any remaining tokens after options are parsed as text. Each token becomes a separate string in the array, but text can be quoted to include multiple words in one token. For example, `"This is one message"` becomes a single token, while `This is four tokens` becomes four separate tokens. Add the following code to create the <xref:System.CommandLine.Option`1?displayProperty=nameWithType> and <xref:System.CommandLine.Argument`1?displayProperty=nameWithType> objects to represent the command line option and argument:

:::code language="csharp" source="./snippets/file-based-programs/AsciiArt.cs" id="OptionArgument":::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to fit the style of a procedure. DO THIS and then follow up with info about why and the code.. I feel like you want to do this but for some reason you didn't 😁


  1. Define the delay option and messages argument. Add the following code to create the CommandLine.Option and CommandLine.Argument objects to represent the command line option and argument:

    :::code language="csharp" source="./snippets/file-based-programs/AsciiArt.cs" id="OptionArgument":::

    In command-line applications, options typically begin with -- (double dash) and can accept arguments. The --delay option accepts an integer argument that specifies the delay in milliseconds. The messagesArgument defines how any remaining tokens after options are parsed as text. Each token becomes a separate string in the array, but text can be quoted to include multiple words in one token. For example, "This is one message" becomes a single token, while This is four tokens becomes four separate tokens.

Comment on lines 1 to 8
This is the input file
for a file based program.
It prints the messages
from a file or the
command line.
There are options you
can choose for ASCII
art and colors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something fun like

Hello from
     _       _              _   
  __| | ___ | |_ _ __   ___| |_ 
 / _` |/ _ \| __| '_ \ / _ \ __|
| (_| | (_) | |_| | | |  __/ |_ 
 \__,_|\___/ \__|_| |_|\___|\__|

This is the input file
for a file based program.
It prints the messages
from a file or the
command line.
There are options you
can choose for ASCII
art and colors.

:::code language="csharp" source="./snippets/file-based-programs/AsciiArt.cs":::

In this tutorial, you learned to build a file-based program, where you build the program in a single C# file. These programs don't use a project file, and can use the `#!` directive on unix systems. Learners can create these programs after trying our [online tutorials](../../tour-of-csharp/tutorials/hello-world.md) and before building larger project-based programs. File based programs are also a great platform for command line utilities.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the code is only around 65 lines of code (with the //snippet comments removed) you could add a section to the end with all the code as an example. If you want to do that you need to prep the file first. You can't just reference the entire file because it will contain the //snippet codes. Add a // <all> and // </all> snippet at the top and bottom of the file, respectively. Then reference the all snippet in the ::: code reference. This erases all of the other //snippet comments in the output.

BillWagner and others added 8 commits August 12, 2025 17:09
set the `+x` permission on the file-based program.

Fix build warnings.
Use extracted code snippets instead of inline code.
Co-authored-by: Andy (Steve) De George <[email protected]>
@BillWagner BillWagner force-pushed the file-program-tutorial branch from 0ce87e9 to 9b68cdf Compare August 12, 2025 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[C# 14-Tutorials]: New Feature - file-based programs
2 participants