Advertisement
winone1208

Funkcje i konwersja C#

Jul 8th, 2020
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Funkcje
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double liczba = 8.8786;
  10.             var liczba2 = PodwojLiczbe(PrzekonwertujDoubleNaInta(liczba)); //'(int)liczba' z double na int
  11.             Console.WriteLine(liczba2);
  12.             Console.WriteLine();
  13.             int num = 5;
  14.             Console.WriteLine(num);
  15.             Console.WriteLine(PodwojLiczbe(num));
  16.             Console.WriteLine(num);
  17.             Console.WriteLine(PodwojLiczbe1(num, out num));
  18.             Console.WriteLine(num);
  19.  
  20.         }
  21.  
  22.         private static int PodwojLiczbe(int liczba1)
  23.         {
  24.             return liczba1 * 2;
  25.         }
  26.  
  27.         private static int PodwojLiczbe1(int liczba1, out int liczba2) // to fajne
  28.         {
  29.             return liczba2 = liczba1 * 2;
  30.         }
  31.  
  32.         private static int PrzekonwertujDoubleNaInta(double liczba)
  33.         {
  34.             if (int.TryParse(liczba.ToString(), out int liczba2))
  35.             {
  36.                 return liczba2;
  37.             }
  38.             else
  39.             {
  40.                 return 0;
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement