Advertisement
oregtolvaj

Untitled

Nov 20th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1 {
  7.     struct pont {
  8.         public int x;
  9.         public int y;
  10.     }
  11.     struct kocsi {
  12.         public string marka;
  13.         public int kobcenti;
  14.         public double fogyasztas;
  15.     }
  16.     class Program {
  17.         static int maximum(int x, int y) {
  18.             return (x>y)?x:y;
  19.         }
  20.         static void Main(string[] args) {
  21.             Random r = new Random();
  22.             //int v = r.Next();
  23.             //int v = r.Next(10); // 0-10-ig
  24.             //int v = r.Next(10, 100); //10-100
  25.             double v = r.NextDouble();
  26.             Console.Write(v);
  27.             // egész számmá konvertálás
  28.             int szam = Int32.Parse("5");
  29.             //int szam = int.Parse("5");
  30.             int szam2 = Convert.ToInt32("5");
  31.             double ertek = 5.2;
  32.             int szam3 = (int)ertek;
  33.             Console.WriteLine(szam3);
  34.             // tömbök
  35.             int[] tomb1= {1,2,3,4,5};
  36.             int[] tomb2 = new int[5];
  37.             string[] tomb3 = new string[3];
  38.             Console.WriteLine(tomb1[0]);
  39.             tomb2[0] = 5;
  40.             tomb3[0] = "hétfő";
  41.             Console.WriteLine(tomb3.Length);
  42.             // kétdimenziós
  43.             int[,] ketdimenzios = new int[3, 2];
  44.             int[,] ketdimenzios2 = {{1,2},{3,4},{5,6}};
  45.             Console.WriteLine(ketdimenzios2[2,1]);
  46.             // struktúra
  47.            
  48.             pont kezdo = new pont();
  49.             pont veg = new pont();
  50.             kezdo.x = 10;
  51.             kezdo.y = 12;
  52.            
  53.             // kocsik
  54.             kocsi[] kocsik = new kocsi[3];
  55.             /*
  56.             for (int i = 0; i < 3; i++) {
  57.                 Console.WriteLine("Adja meg a kocsi márkáját");
  58.                 kocsik[i].marka = Console.ReadLine();
  59.                 Console.WriteLine("Márka: " + kocsik[i].marka);
  60.  
  61.                 Console.WriteLine("Adja meg a kocsi köbcentijét");
  62.                 kocsik[i].kobcenti = Convert.ToInt32(Console.ReadLine());
  63.                 Console.WriteLine("Köbcenti: " + kocsik[i].kobcenti);
  64.  
  65.                 Console.WriteLine("Adja meg a kocsi fogyasztását");
  66.                 kocsik[i].fogyasztas = Convert.ToDouble(Console.ReadLine());
  67.                 Console.WriteLine("Fogyasztás: " + kocsik[i].fogyasztas);
  68.             }
  69.            */
  70.             // foreach példa
  71.             int[] szamok = new int[] { 1, 2, 3, 4, 5 };
  72.             foreach (int elem in szamok) {
  73.                 if (elem % 2 == 0) Console.WriteLine("a {0} páros szám", elem);
  74.             }
  75.             // switch példa
  76.             int valasz = Convert.ToInt32(Console.ReadLine());
  77.             switch (valasz) {
  78.                 case 0: Console.WriteLine("győzelem");
  79.                     break;
  80.                 case 1: Console.WriteLine("vereség");
  81.                     break;
  82.                 case 2: Console.WriteLine("döntetlen");
  83.                     break;
  84.                 default: Console.WriteLine("hibás adat");
  85.                     break;
  86.  
  87.             }
  88.             // függvények1
  89.             Console.WriteLine(maximum(3, 2));
  90.             // függvények2
  91.  
  92.             Console.ReadLine();
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement