Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Практика створення методів | Методи
Основи C#

book
Практика створення методів

Нижче наведено код для виведення форми трикутника за допомогою кількох операторів Console.WriteLine:

cs

main

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

Створіть новий метод під назвою displayTriangle з наведеним вище кодом і викличте його в основній функції.

cs

main

copy
using System;

namespace ConsoleApp
{
internal class Program
{
// Create a method here

static void Main(string[] args)
{
// Call the function here

}
}
}
123456789101112131415
using System; namespace ConsoleApp { internal class Program { // Create a method here static void Main(string[] args) { // Call the function here } } }
  1. Створіть метод, використовуючи синтаксис static void methodName(), і помістіть код трикутника всередину нього.

Потім виконайте його в основному методі.

cs

main

copy
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();
}
}
}
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(); } } }
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 6. Розділ 3

Запитати АІ

expand
ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

We use cookies to make your experience better!
some-alt