C# Mini Project
Put one label under the sum and the date, and make that label use the sum. The screen you check has three lines: left=10 right=2 sum=12, then 2026-03-05, then pine x12. The third line is the whole project. It is a word you stored and the number Add already returns.
Quality and Wrap-up continues, so Pine, Add, left, and right stay, and the plus still returns 12. The compiling page split one run into dotnet build and dotnet run --no-build, and that screen was four lines, the last of them inRange=True. This page keeps the first two of those lines and takes the die off. If --no-build still shows roll= and inRange=True, the Random lines are still in the file, or you have not built since you deleted them. Build again before you judge pine x12.
One method for the label
Open the PineLab project. The class stays Pine. Keep Add and its four /// lines. Keep the tight sum format and new DateTime(2026, 3, 5). Delete Random rng = new Random();, the Next call, and the two lines that print roll= and inRange=. The project must not wait for typing. pine is written in the file.
Under Add, add a second method. It does not print. It returns the line:
public static string Label(string name, int count)
return name + " x" + count;
Label is PascalCase, like Add. name and count are camelCase, like left and right. The space sits inside the quotes, before the x. There is no format slot on this return. The + between a string and an int writes the int's digits. count is not added to the letters as a sum. It is copied onto the end.
In Main, after the date line, store the word and print the return:
string name = "pine";
Console.WriteLine(Label(name, sum));
Pass sum, not left and not day.Day. sum is 12, so the return is pine x12.
using System;
public class Pine
{
/// <summary>Adds the two stored numbers.</summary>
/// <param name="left">The first number.</param>
/// <param name="right">The second number.</param>
/// <returns>The sum of left and right.</returns>
public static int Add(int left, int right)
{
return left + right;
}
public static string Label(string name, int count)
{
return name + " x" + count;
}
public static void Main()
{
int left = 10;
int right = 2;
int sum = Add(left, right);
Console.WriteLine("left={0} right={1} sum={2}", left, right, sum);
DateTime day = new DateTime(2026, 3, 5);
Console.WriteLine("{0:yyyy-MM-dd}", day);
string name = "pine";
Console.WriteLine(Label(name, sum));
}
}
Three lines
From the PineLab folder, run dotnet build. Success still prints none of the program lines. Main has not run. Then run dotnet run --no-build. The screen shows left=10 right=2 sum=12, then 2026-03-05, then pine x12.
Walk Main once. It stores ten and two. Add returns twelve. The first WriteLine fills three number slots. The date line prints the fixed day. name stores the four letters pine. Label joins those letters, a space, the letter x, and the digits of sum. The last WriteLine prints that return. Nothing in Label changes left, right, or sum. The first line is still the proof that the sum survived.
There is no fourth line. No roll=. No inRange=True. A project you check on every run needs a screen that stays put, so this file does not draw a number.
The 12 in the label is the sum
pine x12 is not a new fact about the date. The 12 is Add(left, right). Change the body of Add to a minus, build, and run with --no-build. The first line ends in 8, and the third line becomes pine x8. One method feeds both lines. Put the plus back, build, and run again so both show 12.
Pass the wrong int and the label moves while the sum line stays. Label(name, left) returns pine x10. Label(name, right) returns pine x2. Label(name, day.Day) returns pine x5, because the day is 5 and the format zeros are not stored on Day. The checked call passes sum.
Drop the space inside " x" and the third line is pinex12. The letters run together. Put the space back. The x is a letter you typed in the return. It is not a format slot and it is not a variable.
A method you never call prints nothing
Label returns a string. It does not write a line. If Main never calls it, the method sits in the class and the screen has only the sum and the date. A public method with no call is not a compile error. The missing line is the clue. Put Console.WriteLine(Label(name, sum)); back.
If the third line is pine x12 but you cannot find Label in the file, the writing line has the whole sentence in quotes: Console.WriteLine("pine x12");. That line cannot follow a change to Add. The checked file builds the line from name and sum.
name is a local in Main. count is a parameter of Label. They are different names for a reason. Main does not see count, and Label does not see name until you pass it. That is the scope page, still true in a project this small.
An old build hides the label
Add Label, save, and run dotnet run --no-build without a new dotnet build. You are still running the program compiling left behind. The screen can show roll= and inRange=True, and it will not show pine x12. The editor has the new method. The program you ran does not. dotnet build, then --no-build again. The third line appears only after that build.
If the build fails, read the line it names. A missing semicolon stops the build, and none of the three lines appear. A wrong word such as Lable is a different problem: the call does not match the method, and the build fails the same way. Fix the spelling. Do not start a second project.
Stay in PineLab, the folder with the .csproj. The class is Pine and the project is PineLab. Those names were allowed to differ on the compiling page, and they still differ here.
What the project leaves out
This file uses a class, two methods, a format line, a fixed date, and one string join. It does not use a loop, a list, a file, or try. Those tools stay on their own pages. Pasting them in to make the project look bigger hides the three lines.
It also does not wait on Console.ReadLine. The input page taught a typed line. Here the word has to be pine on every run, so it is stored in quotes. If the program waits and prints nothing until you type, a ReadLine is still in Main. Delete it.
It does not roll a die. If you liked inRange=True, that check is on the random page. This project trades that moving line for a line you can match exactly.
Program arguments stay shut
You can build Pine, run the last build, and read three lines: the sum, the day, and pine x12. The next page is program arguments. It reads words you type after the run command, instead of storing pine in the file. This page stops before that. Main has no string[] args. Do not add a parameter to Main here. The checked word comes from string name = "pine";.
One last pass: no Random, no ReadLine, Add returns left + right, Label returns name + " x" + count, the call passes sum, you are in PineLab, dotnet build succeeds, and dotnet run --no-build shows left=10 right=2 sum=12, then 2026-03-05, then pine x12. When those three lines match, the mini project did its job.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top