Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Methods Creation Practice | Methods
C# Basics
course content

Contenido del Curso

C# Basics

C# Basics

1. Getting Started
2. Dealing with Data Types
3. Control Structures
4. Loops
5. Arrays
6. Methods

bookMethods Creation Practice

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

cs

main

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.

cs

main

copy
123456789101112131415
using System; namespace ConsoleApp { internal class Program { // Create a method here static void Main(string[] args) { // Call the function here } } }
  1. Create a method using static void methodName() syntax and put the triangle code inside it. Afterwards, execute it in the main method.
cs

main

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(); } } }

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 6. Capítulo 3
some-alt