Prática de Criação de Métodos
A seguir está um código para exibir uma forma de triângulo usando várias instruções Console.WriteLine
:
main
9
1
2
3
4
5
Console.WriteLine("*********");
Console.WriteLine("*******");
Console.WriteLine("*****");
Console.WriteLine("***");
Console.WriteLine("*");
12345Console.WriteLine("*********"); Console.WriteLine("*******"); Console.WriteLine("*****"); Console.WriteLine("***"); Console.WriteLine("*");
Crie um novo método chamado displayTriangle
com o código acima e chame-o na função principal.
main
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
namespace ConsoleApp
{
internal class Program
{
// Create a method here
static void Main(string[] args)
{
// Call the function here
}
}
}
123456789101112131415using System; namespace ConsoleApp { internal class Program { // Create a method here static void Main(string[] args) { // Call the function here } } }
Crie um método usando a sintaxe
static void methodName()
e coloque o código do triângulo dentro dele.
Em seguida, execute-o no método principal.
main
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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();
}
}
}
1234567891011121314151617181920212223using 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(); } } }
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 6. Capítulo 3
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo