Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Methods Creation | Methods
C# Basics

bookChallenge: Methods Creation

Following is a code for outputting a triangle shape using multiple Console.WriteLine statements:

main.cs

main.cs

copy
12345
Console.WriteLine("*********"); Console.WriteLine("*******"); Console.WriteLine("*****"); Console.WriteLine("***"); Console.WriteLine("*");

Create a new method called displayTriangle with the above code and call it in the main function.

main.cs

main.cs

copy
123456789101112131415
using System; namespace ConsoleApp { internal class Program { // Create a method here static void Main(string[] args) { // Call the function here } } }

Create a method using static void methodName() syntax and put the triangle code inside it. Afterwards, execute it in the main method.

main.cs

main.cs

copy
1234567891011121314151617181920212223
using System; namespace ConsoleApp { internal class Program { // Create a method here static void displayTriangle() { Console.WriteLine("*********"); Console.WriteLine("*******"); Console.WriteLine("*****"); Console.WriteLine("***"); Console.WriteLine("*"); } static void Main(string[] args) { // Call the method here displayTriangle(); } } }

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 6. Kapittel 3

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

Can you show me the triangle code that should go inside the method?

What should the triangle look like when printed?

Do you want the full code including the Main method?

Awesome!

Completion rate improved to 1.59

bookChallenge: Methods Creation

Sveip for å vise menyen

Following is a code for outputting a triangle shape using multiple Console.WriteLine statements:

main.cs

main.cs

copy
12345
Console.WriteLine("*********"); Console.WriteLine("*******"); Console.WriteLine("*****"); Console.WriteLine("***"); Console.WriteLine("*");

Create a new method called displayTriangle with the above code and call it in the main function.

main.cs

main.cs

copy
123456789101112131415
using System; namespace ConsoleApp { internal class Program { // Create a method here static void Main(string[] args) { // Call the function here } } }

Create a method using static void methodName() syntax and put the triangle code inside it. Afterwards, execute it in the main method.

main.cs

main.cs

copy
1234567891011121314151617181920212223
using System; namespace ConsoleApp { internal class Program { // Create a method here static void displayTriangle() { Console.WriteLine("*********"); Console.WriteLine("*******"); Console.WriteLine("*****"); Console.WriteLine("***"); Console.WriteLine("*"); } static void Main(string[] args) { // Call the method here displayTriangle(); } } }

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 6. Kapittel 3
some-alt