ProgaOra/20231113/ConsoleApp1/Program.cs
2023-12-04 10:51:29 +01:00

90 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Szemely
{
public string Name { get; set; }
public int Age { get; set; }
public void Kiiras()
{
Console.WriteLine($"Név: {Name}, Kor: {Age}");
}
}
class Adatok
{
private string[] adat;
// Konstruktor az osztály inicializálásához
public Adatok()
{
// Példányváltozó inicializálása
adat = new string[5];
}
public string this[int index]
{
get
{
// Ellenőrzés, hogy az index a megfelelő tartományban van-e
if (index >= 0 && index < adat.Length)
{
return adat[index];
} else
{
return "Érvénytelen index";
}
}
set
{
//Ellenőrzés hogy az index a megfelelő tartományban van-e
if (index >= 0 && index < adat.Length)
{
adat[index] = value;
}
else
{
Console.WriteLine("Érvénytelen index");
}
}
}
}
class Program
{
static void KiirasEgyen(Szemely person)
{
Console.WriteLine("Személy adatai:");
person.Kiiras();
}
static void Main(string[] args)
{
Adatok elem = new Adatok();
elem[0] = "Első";
elem[1] = "Második";
elem[2] = "Harmadik";
Console.WriteLine(elem[0]);
Console.WriteLine(elem[1]);
Console.WriteLine(elem[2]);
Console.WriteLine(elem[5]);
Szemely egyen = new Szemely {
Name = "Füty Imre",
Age = 12
};
KiirasEgyen(egyen);
}
}
}