Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1 {
- struct pont {
- public int x;
- public int y;
- }
- struct kocsi {
- public string marka;
- public int kobcenti;
- public double fogyasztas;
- }
- class Program {
- static int maximum(int x, int y) {
- return (x>y)?x:y;
- }
- static void Main(string[] args) {
- Random r = new Random();
- //int v = r.Next();
- //int v = r.Next(10); // 0-10-ig
- //int v = r.Next(10, 100); //10-100
- double v = r.NextDouble();
- Console.Write(v);
- // egész számmá konvertálás
- int szam = Int32.Parse("5");
- //int szam = int.Parse("5");
- int szam2 = Convert.ToInt32("5");
- double ertek = 5.2;
- int szam3 = (int)ertek;
- Console.WriteLine(szam3);
- // tömbök
- int[] tomb1= {1,2,3,4,5};
- int[] tomb2 = new int[5];
- string[] tomb3 = new string[3];
- Console.WriteLine(tomb1[0]);
- tomb2[0] = 5;
- tomb3[0] = "hétfő";
- Console.WriteLine(tomb3.Length);
- // kétdimenziós
- int[,] ketdimenzios = new int[3, 2];
- int[,] ketdimenzios2 = {{1,2},{3,4},{5,6}};
- Console.WriteLine(ketdimenzios2[2,1]);
- // struktúra
- pont kezdo = new pont();
- pont veg = new pont();
- kezdo.x = 10;
- kezdo.y = 12;
- // kocsik
- kocsi[] kocsik = new kocsi[3];
- /*
- for (int i = 0; i < 3; i++) {
- Console.WriteLine("Adja meg a kocsi márkáját");
- kocsik[i].marka = Console.ReadLine();
- Console.WriteLine("Márka: " + kocsik[i].marka);
- Console.WriteLine("Adja meg a kocsi köbcentijét");
- kocsik[i].kobcenti = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Köbcenti: " + kocsik[i].kobcenti);
- Console.WriteLine("Adja meg a kocsi fogyasztását");
- kocsik[i].fogyasztas = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Fogyasztás: " + kocsik[i].fogyasztas);
- }
- */
- // foreach példa
- int[] szamok = new int[] { 1, 2, 3, 4, 5 };
- foreach (int elem in szamok) {
- if (elem % 2 == 0) Console.WriteLine("a {0} páros szám", elem);
- }
- // switch példa
- int valasz = Convert.ToInt32(Console.ReadLine());
- switch (valasz) {
- case 0: Console.WriteLine("győzelem");
- break;
- case 1: Console.WriteLine("vereség");
- break;
- case 2: Console.WriteLine("döntetlen");
- break;
- default: Console.WriteLine("hibás adat");
- break;
- }
- // függvények1
- Console.WriteLine(maximum(3, 2));
- // függvények2
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement