C# Methods
Write a method named ring that writes one word: ding. Put those writing lines under static void ring() with empty parentheses. Inside Main, write only ring(); — the name, then empty parentheses, then a semicolon. Run the program. The screen should show one line: ding. Main does not hold the WriteLine for ding. The method does. That split is what this page teaches. Keep the public class named Pine.
Lines that live under ring
Until now, most of your writing work sat directly inside Main. That still works. A method gives the same lines a name of their own. You write the lines once under that name. Then Main asks for them by writing the name as a call.
Open the Pine file. The class name stays Pine. This page does not rename the type. Delete any foreach that walks plants or slots if that shape is still there. Delete a counted for with break or continue if it is still there. Delete any ReadLine line. The file you keep has no wait for typing and no leftover loop demo in Main.
Outside Main, still inside the class braces, you will write static void ring() with a body that runs Console.WriteLine("ding");. The full program is in the next box so you can copy it cleanly.
The word static stays on this beginner shape so Main can call ring without building an object. The word void means this method does not hand a value back to the caller — it only runs its body. The name ring is the label you will type in Main. The empty parentheses () mean this page’s method takes no values in. The braces hold the body. Save the file before you run.
The file you keep
Here is the full small program for this page. Main holds only the call. ring holds the writing line. There is no index counter and no array walk in this kept file.
using System;
public class Pine
{
public static void Main()
{
ring();
}
static void ring()
{
Console.WriteLine("ding");
}
}
Read it from the top. using System; prepares short names. public class Pine names the type. public static void Main() is where the runtime starts. The only statement in Main is ring();. Below Main, still inside the class, static void ring() holds Console.WriteLine("ding");. One line on the screen: ding.
Run it with dotnet run. The program writes one line and stops. It does not wait for you to type. If dotnet run waits, ReadLine is still in the file. Delete that line and keep ring(); in Main plus the ring method above. The screen shows ding. If the screen shows leaf and mint, a foreach leftover is still writing. If the screen shows the letters ring, a writing line has quotes around that word: Console.WriteLine("ring");. You do not reinstall the .NET SDK for a screen that shows the wrong line.
Walk one full run in order. C# starts at Main. The only statement in Main is ring();. That call jumps into the ring method. Inside ring, WriteLine writes ding. Then ring finishes, and Main has nothing left, so the program ends. You did not put Console.WriteLine("ding"); inside Main on this page. You put it under ring and asked for it by name. If the screen shows ding, the call reached the body. If the screen stays blank after a clean build, Main never called ring.
Think of ring as a labeled shelf for the writing lines. Main does not need to repeat those lines. It only needs the shelf name written as a call. That is why a short Main can still produce a clear screen line: the work lives under the method name, and the call is the request. Once that pattern is clear, adding another call is only another request to the same shelf of writing lines.
Call ring from Main more than once
Change only Main so it calls the same method twice. Leave the ring method itself alone. The body still writes ding once per call.
using System;
public class Pine
{
public static void Main()
{
ring();
ring();
}
static void ring()
{
Console.WriteLine("ding");
}
}
This is the second file. It is not the file you keep for the one-call shape, but it teaches the same method. Run dotnet run. The screen should show two lines, each saying ding. The first call runs the body once. The second call runs the same body again. That reuse is the reason to name the lines. You did not copy the WriteLine a second time under ring. You wrote a second call in Main.
If you leave only one ring();, the screen returns to a single ding. The method definition does not write by itself. Only a call from Main runs the body. A file that defines ring but never calls it can build and still show a blank screen when you run. After you have seen two lines, put the kept one-call file back if that is the shape you want to save: one ring(); in Main.
Pieces of a method header
On this page the header is static void ring(). Read it left to right. static lets Main call the method on this beginner shape. void means no value comes back through the call. ring is the name. () are empty on purpose: this session does not pass words or numbers into the method. The next page, parameters, puts names inside those parentheses. The page after that, return, changes void when you need a value back. Keep both of those for later. Today the empty () and void are enough.
📊 Header piece on this page
| Piece | On this page |
|---|---|
static |
Main can call ring without an object |
void |
ring does not hand a value back |
ring |
the name you type in the call |
() |
no values go in on this page |
{ ... } |
the body that writes ding |
The call in Main must match the name exactly: ring(); with a lowercase r, empty parentheses, and a semicolon. Writing Ring(); with a capital R is a different name to C#. Writing ring without () is not a call on this shape. Writing Console.WriteLine("ring"); writes the four letters of the word ring; it does not run the method body. Keep the call as ring(); when you want ding on the screen.
A common leftover is an old foreach plants walk still sitting in Main beside the new call. Then the screen may show leaf and mint, or 2, 4, and 6, instead of ding — or both kinds of lines mixed. Clear Main down to the ring(); calls this lesson needs. Another mix-up is putting the method inside Main’s braces. Methods on this page sit inside the class, next to Main, not nested inside Main.
foreach from the previous page walked values already stored in an array. This page does not walk an array. It names a void method and calls it. Do not leave foreach (string plant in plants) in the same Main and wonder why the screen shows leaf instead of ding. This session’s kept Main should hold the ring(); call only. The method body holds the writing line for ding.
You can now write static void ring(), put a WriteLine in its braces, and call ring() from Main so the screen shows ding. Calling twice writes ding twice without copying the body. Empty parentheses and void stay on this page on purpose. The next page is parameters, where names go inside the parentheses so the method can use values you pass from Main.
The screen is the method body
The file you keep writes ding once when Main has one call. The name ring is in the call, and the letters ring are not on the screen as the printed word unless you quoted them. Empty () sit on both the header and the call. Nesting ring inside Main is not the shape this lesson builds.
🧠 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