Tartalom jegyzék:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gyakorlas
{
internal class Program
{
static void Main(string[] args)
{
string a = "Hello";
string b = "World";
Console.WriteLine("Hello World!");
Console.WriteLine(a+" "+b+"!");
Console.WriteLine("{0} {1}!",a, b);
Console.WriteLine($"{a} {b}!");
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gyakorlas
{
internal class Program
{
static void Main(string[] args)
{
int i;
for(i = 0; i<10; i++)
{
Console.WriteLine(i);
}
int j = 0;
while (j < 10)
{
Console.WriteLine(j);
j++;
}
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gyakorlas
{
internal class Program
{
static void Main(string[] args)
{
int[] tomb = new int[] { 1, 45, 83, 23, 45, 62, 76, 4, 11, 78 };
int i;
int darab = 0;
for (i = 0; i < tomb.Length; i++)
{
if (tomb[i] > 50)
{
darab++;
}
}
Console.WriteLine($"A tömb-ben {darab}db 50-nél nagyobb szám van.");
Console.ReadKey();
}
}
}
Összegzés tétele:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gyakorlas
{
internal class Program
{
static void Main(string[] args)
{
int[] tomb = new int[] { 1, 45, 83, 23, 45, 62, 76, 4, 11, 78 };
int i;
int osszeg = 0;
for (i = 0; i < tomb.Length; i++)
{
osszeg = osszeg + tomb[i];
}
Console.WriteLine($"A tömb elemeinek összege: {osszeg}");
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gyakorlas
{
internal class Program
{
static void Main(string[] args)
{
int[] tomb = new int[] { 1, 45, 83, 23, 45, 62, 76, 4, 11, 78 };
int i;
int min = tomb[0];
int max = tomb[0];
for (i = 0; i < tomb.Length; i++)
{
if (tomb[i] > max)
{
max = tomb[i];
}
}
Console.WriteLine($"A tömb-ben a legkisebb szám: {min}");
Console.WriteLine($"A tömb-ben a legnagyobb szám: {max}");
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gyakorlas
{
internal class Program
{
static void Main(string[] args)
{
int[] tomb = new int[] { 1, 45, 83, 23, 45, 62, 76, 4, 11, 78 };
int i = -1;
int keres = 23; // ez a keresett szám a tömbben
bool l = false;
while(i<tomb.Length-1 && !l)
{
i++;
if (tomb[i] == keres)
{
l = true;
}
}
if (l)
{
Console.WriteLine("Benne van a keresett szám a tömbben!");
}
else { Console.WriteLine("A keresett szám nincs a tömbben!"); }
Console.ReadKey();
}
}
}
using System;
class Program
{
static void Main(){
int a;
int kerulet;
int terulet;
Console.WriteLine("Adjuk meg a négyzet oldalát");
a = int.Parse(Console.ReadLine());
kerulet = a * 4;
terulet = a * a;
Console.WriteLine("A négyzet kerülete " + kerulet + "cm.");
Console.WriteLine("A négyzet területe " + terulet + "cm2");
Console.WriteLine("A négyzet területe " + KerulteSzamol(a) + "cm");
Console.WriteLine("A négyzet területe " + TeruletSzamol(a) + "cm2");
KerulteSzamol(a);
}
static int KerulteSzamol(int oldal){
return oldal * 4;
}
static int TeruletSzamol(int oldal){
return oldal * oldal;
}
}
using System;
using System.Collections.Generic;
using System.Text;
class Geometria
{
static void Main(){
int a;
int b;
int r;
Console.WriteLine("Adjuk meg a téglalap 2 oldalát");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
Console.WriteLine("A téglalp kerülete " + TeglalapKeruletSzamol(a, b) + "cm");
Console.WriteLine("A téglalp kerülete " + TeglalapTeruletSzamol(a, b) + "cm2\n");
Console.WriteLine("Adjuk meg a kör sugarát");
r = int.Parse(Console.ReadLine());
Console.WriteLine("A kör kerülete " + Math.Round(KorKeruletSzamol(r),2) + "cm");
Console.WriteLine("A kör területe " + Math.Round(KorTeruletSzamol(r),2) + "cm2\n");
Console.WriteLine("A gömb felszine " + Math.Round(GombFelszinSzamol(r), 2) + "cm");
Console.WriteLine("A gömb térfogata " + GombFelszinSzamol(r) + "cm3");
}
static int TeglalapKeruletSzamol(int oldal1, int oldal2){
return 2 * (oldal1 + oldal2);
}
static int TeglalapTeruletSzamol(int oldal1, int oldal2){
return oldal1 * oldal2;
}
static double KorKeruletSzamol(int sugar){
return 2 * sugar * Math.PI;
}
static double KorTeruletSzamol(int sugar){
return sugar * sugar * Math.PI;
}
static double GombFelszinSzamol(int sugar){
return 4 * sugar * sugar * Math.PI;
}
static double GombTerfogatSzamol(int sugar){
return 4 * sugar * sugar * sugar * Math.PI / 3;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tombellenorzes
{
internal class Program
{
static void Main(string[] args)
{
int[] tomb = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int keres = tomb[0];
bool logic = false;
int i;
int j = 0;
for (i = 0; i < tomb.Length; i++)
{
Console.Write(tomb[i] + " ");
}
while( j<tomb.Length-1 && !logic)
{
j++;
if(keres == tomb[j])
{
logic = true;
}
else
{
keres = tomb[j];
}
}
if (logic)
{
Console.WriteLine("Van egyezés");
}
else
{
Console.WriteLine("Nincs egyezés!");
}
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Data;
//using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
//https://github.com/znyisztor77/consoleapp_mysqlconnect.git
namespace consoleapp_mysqlconnect
{
internal class Program
{
static void Main(string[] args)
{
string connectionString = "server=localhost;uid=root;" + "password=;database=szerszamok";
// Adatbázis elérése
using (var connection = new MySqlConnection(connectionString))
{
try
{
connection.Open();
string query = "SELECT * FROM szerszamok";
var cmd = new MySqlCommand(query, connection);
var reader = cmd.ExecuteReader();
// Adatok kiírása
while (reader.Read())
{
Console.WriteLine("{0} - {1} - {2} db - {3} Ft",
reader["szeszamid"], reader["megnevezes"], reader["darabszam"], reader["egysegar"]);
}
Console.ReadKey();
}
catch (MySqlException ex)
{
Console.WriteLine("Hiba az adatbázishoz való kapcsolódás során: {0}", ex.Message);
Console.ReadLine(); }
finally
{
// Biztosítja a kapcsolat lezárását kivétel esetén is
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}
}
}
}
}
Szükséges: NuGet Package -> Newtonsoft.Json
Program.cs fájl tartalma
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using RestApi_03._05;
namespace RestApi_03._05
{
class Program
{
static string endPointUrl = "https://retoolapi.dev/KqpqJ9/data";
static List<Adat> adatok = new List<Adat>();
static void Main(string[] args)
{
//https://app.quicktype.io/ api alap kód generálás c#-hoz
//https://merlinvizsga.hu/index.php?menu=syncAsync
restapiAdatok().Wait();
foreach(Adat item in adatok)
{
Console.WriteLine($"{item.Id}, {item.Name}, {item.Salary}");
}
legjobbanKereso();
Console.WriteLine("Program vége!");
Console.ReadLine();
}
static async Task restapiAdatok()
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, endPointUrl);
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
// Console.WriteLine(await response.Content.ReadAsStringAsync());
string jsonString = await response.Content.ReadAsStringAsync();
adatok = Adat.FromJson(jsonString).ToList();
}
private static void legjobbanKereso()
{
long maxSalary = adatok.Max(a => a.Salary);
Adat legmagasabb = adatok.Find(a => a.Salary == maxSalary);
Console.WriteLine("1. feladat");
Console.WriteLine($"\t A legjobban kereső dolgozo {legmagasabb.Name}, a fizetése: {legmagasabb.Salary}");
}
}
}
Adat.cs fájl tartalma
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using RestApi_03._05;
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using RestApi_03._05;
//
// var adat = Adat.FromJson(jsonString);
namespace RestApi_03._05
{
public partial class Adat
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("salary")]
public long Salary { get; set; }
}
public partial class Adat
{
public static Adat[] FromJson(string json) => JsonConvert.DeserializeObject<Adat[]>(json, RestApi_03._05.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this Adat[] self) => JsonConvert.SerializeObject(self, RestApi_03._05.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
}
https://github.com/znyisztor77/Adatbazis_Winform_Datagridview.git
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySqlConnector;
namespace Adatbazis_Winform_Datagridview
{
public partial class Form1 : Form
{
MySqlConnection dbConnection;
public Form1()
{
InitializeComponent();
string connectionString;
string sqlCommand;
connectionString = "server=localhost;userid=root;password=;database=tallest_buildings";
dbConnection = new MySqlConnection(connectionString);
sqlCommand = "SELECT rank, building_name, floors FROM buildings WHERE 1; ";
dbConnection.Open();
MySqlDataAdapter adapter = new MySqlDataAdapter(sqlCommand,dbConnection);
DataSet ds = new DataSet();
adapter.Fill(ds);
BindingSource bs = new BindingSource();
bs.DataSource = ds.Tables[0];
dataGridView1.DataSource = bs;
}
private void button1_orszag_Click(object sender, EventArgs e)
{
string adat = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
string sqlParancs = "SELECT city FROM buildings WHERE building_name ='" +adat+"';" ;
MySqlCommand sqlCommand = new MySqlCommand(sqlParancs, dbConnection);
string varos = sqlCommand.ExecuteScalar().ToString();
label1.Text = "Orszag: " + varos;
}
private void button1_Click(object sender, EventArgs e)
{
string adat = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
string sqlParancs = "SELECT COUNT(building_name) FROM buildings WHERE height_m >400 ;";
MySqlCommand sqlCommand = new MySqlCommand(sqlParancs, dbConnection);
string varos = sqlCommand.ExecuteScalar().ToString();
label2.Text = "A 400 m-nél magasabb épületek száma: " + varos;
}
}
}
https://github.com/znyisztor77/LastCsharp_csv_console_05.02.git
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace LastCsharp_csv_console_05._02
{
class Program
{
static List<Epulet> epuletek = new List<Epulet>();
static void Main(string[] args)
{
fileBeolvas();
//fileKiiras(epuletek);
Console.WriteLine("1 feladat: ");
Console.WriteLine($"A bolvasott épületek szama: {epuletek.Count}");
Console.WriteLine("\n2. feladat: ");
noTower();
Console.WriteLine("\n4. feladat: ");
feladat04();
Console.ReadKey();
}
private static void feladat04()
{
int osszMagassag = 0;
Console.Write("Add meg az évszámot:");
int evszam = int.Parse(Console.ReadLine());
foreach (Epulet item in epuletek)
{
if (item.Epitesev < evszam)
{
osszMagassag = item.Magassag_ft + osszMagassag;
}
}
Console.WriteLine($"Az összmagassága {osszMagassag} az {evszam} előtti épületeknek.");
}
private static void noTower()
{
int darab = 0;
foreach (Epulet item in epuletek)
{
if (!item.Nev.Contains("Tower"))
{
darab++;
}
}
Console.WriteLine($"{darab}db neve nem tartalmazza a Tower szót.");
}
private static void fileBeolvas()
{
string filename = "100_tallest_javitott4.csv";
using (StreamReader reader = new StreamReader(filename))
{
while (!reader.EndOfStream)
{
string[] sor = reader.ReadLine().Split(';');
//Console.WriteLine(sor[1]);
Epulet epulet = new Epulet(int.Parse(sor[0]), sor[1], sor[2], decimal.Parse(sor[3]), int.Parse(sor[4]), int.Parse(sor[5]), int.Parse(sor[6]));
epuletek.Add(epulet);
}
}
}
private static void fileKiiras(List<Epulet> epuletek)
{
foreach (Epulet item in epuletek)
{
Console.WriteLine($"{item.Nev}");
}
}
}
}
Konstruktor:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LastCsharp_csv_console_05._02
{
class Epulet
{
int rang;
string nev;
string varos_orszag;
decimal magassag_m;
int magassag_ft;
int emeletekszama;
int epitesev;
public bool Tutiepulet()
{
bool status = false;
if (magassag_m>500 && emeletekszama>100)
{
status = true;
}
return status;
}
public Epulet(int rang, string nev, string varos_orszag, decimal magassag_m, int magassag_ft, int emeletekszama, int epitesev)
{
this.Rang = rang;
this.Nev = nev;
this.Varos_orszag = varos_orszag;
this.Magassag_m = magassag_m;
this.Magassag_ft = magassag_ft;
this.Emeletekszama = emeletekszama;
this.Epitesev = epitesev;
}
public int Rang { get => rang; set => rang = value; }
public string Nev { get => nev; set => nev = value; }
public string Varos_orszag { get => varos_orszag; set => varos_orszag = value; }
public decimal Magassag_m { get => magassag_m; set => magassag_m = value; }
public int Magassag_ft { get => magassag_ft; set => magassag_ft = value; }
public int Emeletekszama { get => emeletekszama; set => emeletekszama = value; }
public int Epitesev { get => epitesev; set => epitesev = value; }
}
}
https://github.com/znyisztor77/Dolgozok_Console_Winform.git
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Dolgozok_Console_Winform
{
class Program
{
static List<Dolgozo> dolgozok = new List<Dolgozo>();
static void Main(string[] args)
{
beolvasas();
feladat01(); //Hány fő dolgozó
feladat02(); //Legmagasabb keresetű dolgozó neve
feladat03(); //Egyes részlegeken hányan dolgoznak
feladat04(); //Az asztalos műhelybe dolgozók neve
//kiiras(dolgozok);
Console.WriteLine("Program vége!");
Console.ReadKey();
}
private static void feladat04()
{
Console.WriteLine("4. feladat:");
foreach (var item in dolgozok.FindAll(x => x.reszleg == "asztalosműhely"))
{
Console.WriteLine($"\t{item.nev}");
}
}
private static void feladat03()
{
Console.WriteLine("3. feladat:");
foreach(var item in dolgozok.GroupBy(x => x.reszleg).Select(y => new {reszleg =y.Key , letszam = y.Count() } ))
{
Console.WriteLine($"\t{item.reszleg}: {item.letszam}");
}
}
private static void feladat02()
{
Console.WriteLine("2. feladat:");
Dolgozo max = dolgozok.Find(x => x.ber == dolgozok.Max(y => y.ber)); //lambda operator
Console.WriteLine($"\t A{max.nev} dolgozo fizetése:{max.ber} Ft");
}
private static void feladat01()
{
Console.WriteLine("1. feladat:");
Console.WriteLine($"\t A dogozók száma {dolgozok.Count} fő.");
}
private static void kiiras(List<Dolgozo> dolgozok)
{
foreach (Dolgozo item in dolgozok)
{
Console.WriteLine(item.nev);
}
}
private static void beolvasas()
{
string filename = "dolgozok.csv";
using (StreamReader reader = new StreamReader(filename))
{
reader.ReadLine(); // fejléc átugrása
while (!reader.EndOfStream)
{
string[] line = reader.ReadLine().Replace('"',' ').Split(',');
Dolgozo dolgozo = new Dolgozo(line[0].Trim(), line[1].Trim(), line[2].Trim(), int.Parse(line[3].Trim()),int.Parse(line[4].Trim()));
dolgozok.Add(dolgozo);
}
}
}
}
}
Konstruktor:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dolgozok_Console_Winform
{
class Dolgozo
{
//"nev","neme","reszleg","belepesev","ber"
public string nev;
public string neme;
public string reszleg;
public int belepesev;
public int ber;
public Dolgozo(string nev, string neme, string reszleg, int belepesev, int ber)
{
this.nev = nev;
this.neme = neme;
this.reszleg = reszleg;
this.belepesev = belepesev;
this.ber = ber;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Fajlbol_beolvasás
{
class FajlbolOlvasas
{
static void Main()
{
//A .txt szöveges fájlt a bin/Debug/ mappába kell elhelyezni vagy meg adni a szöveges fájl elérési utvonalát
string fajlnev = "szamok.txt";
List<int> adatok = FajlbolSzamok(fajlnev);
Console.WriteLine(string.Join("," , adatok));
}
static List<int> FajlbolSzamok(string fnev)
{
List<int> szamok = new List<int>();
string sor;
using(StreamReader olvaso = new StreamReader(fnev))
{
//sor = olvaso.ReadLine();
// while (sor !=null)
//while(!olvaso.EndOfStream)
while ((sor = olvaso.ReadLine()) != null)
{
szamok.Add(int.Parse(sor));
}
}
return szamok;
}
}
}