Referencje

0

**Mam referencje ... się skompilowało ale mnie nie pokroją błędy jakie debugger wykazuje , Proszę o poradę lub poprawkę ThX:)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zadane_1
{
    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zadanie_na_lekcji
{
    class Program    /// Uzywac referencji  / Bez użycia break  
    {
        //Metoda główna 
        static void Main(string[] args)
        {
            Console.Write("Podaj Podstawe A= ");
            int a = Convert.ToInt16(Console.ReadLine());
            Console.Write("Podaj Podstawe B= ");
            int b = Convert.ToInt16(Console.ReadLine());
            Console.Write("Podaj Wysokość Trapezu H=");
            int h = Convert.ToInt16(Console.ReadLine());
       
            int pole = 0;

            Console.WriteLine("Pole Trapezu to {0}", trapez());
            Console.ReadKey();
        }


//Metoda obliczająca pole trapezu
        static int trapez(ref int pole, int  a,int b, int h )
        {
            pole = (a + b)*(h/2);
        }


    }
}}

 
1
  1. Masz usingi i dwa zagnieżdżone w sobie deklaracje namespace;
  2. Odwołujesz się do metody trapez(), która wymaga czterech parametrów (w tym jeden przez referencję), a ty dajesz zero;
  3. Funkcja trapez() nie zwraca wyniku;
  4. A skoro masz używać referencji, to raczej powinno się użyć funkcji typu void niż typu int;
  5. Tutaj to raczej są parametry wyjściowe, dla których używa się słowa kluczowego out, niż ref - ale nie wiem czy o tym było na lekcji ;-)
  6. Nie pokazują ci się błędy? To źle, zrób tak, aby się pokazywały.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zadanie_na_lekcji
{
    class Program    /// Uzywac referencji  / Bez użycia break  
    {
        //Metoda główna 
        static void Main(string[] args)
        {
            Console.Write("Podaj Podstawe A= ");
            int a = Convert.ToInt16(Console.ReadLine());
            Console.Write("Podaj Podstawe B= ");
            int b = Convert.ToInt16(Console.ReadLine());
            Console.Write("Podaj Wysokość Trapezu H=");
            int h = Convert.ToInt16(Console.ReadLine());

            int pole = 0;
            trapez(ref pole, a, b, h);

            Console.WriteLine("Pole Trapezu to {0}", pole);
            Console.ReadKey();
        }


        //Metoda obliczająca pole trapezu
        static void trapez(ref int pole, int a, int b, int h)
        {
            pole = (a + b) * (h / 2);
        }


    }
}
0

No proszę,
będzie piątka ;-)

1 użytkowników online, w tym zalogowanych: 0, gości: 1