Listák használata
This commit is contained in:
25
Listak/Listak.sln
Normal file
25
Listak/Listak.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.11.35222.181
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Listak", "Listak\Listak.csproj", "{765CF942-185F-4804-8D73-9F53210946CD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{765CF942-185F-4804-8D73-9F53210946CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{765CF942-185F-4804-8D73-9F53210946CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{765CF942-185F-4804-8D73-9F53210946CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{765CF942-185F-4804-8D73-9F53210946CD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E18CA4B6-0528-45BE-970F-4227CD936C76}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
10
Listak/Listak/Listak.csproj
Normal file
10
Listak/Listak/Listak.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
73
Listak/Listak/Program.cs
Normal file
73
Listak/Listak/Program.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
namespace Listak
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
List<int> szamok=new List<int>();
|
||||
List<int> szamok2 = new List<int>();
|
||||
|
||||
Console.WriteLine($"Elemszám:{szamok.Count}");
|
||||
szamok.Add(123);
|
||||
szamok.Add(56);
|
||||
szamok.Add(-129);
|
||||
|
||||
Console.WriteLine($"Elemszám:{szamok.Count}");
|
||||
|
||||
Console.WriteLine($"Indexelhető:{szamok[1]}");
|
||||
|
||||
//Törlés érték szerint
|
||||
szamok.Remove(-129);
|
||||
|
||||
//Törlés index szerint
|
||||
szamok.RemoveAt(1);
|
||||
szamok2.Add(33);
|
||||
szamok2.Add(79);
|
||||
szamok2.Add(122);
|
||||
|
||||
szamok.AddRange(szamok2);
|
||||
|
||||
Console.WriteLine($"Elemszám:{szamok.Count}");
|
||||
|
||||
for (int i = 0; i < szamok.Count; i++)
|
||||
{
|
||||
Console.Write(szamok[i]+" ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
foreach (var i in szamok)
|
||||
{
|
||||
Console.Write(i+" ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine($"Összeg:{szamok.Sum()},Átlag:{szamok.Average()},Min:{szamok.Min()},Max:{szamok.Max()}");
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
szamok.Add(random.Next(-100, 100));
|
||||
}
|
||||
|
||||
//Gyűjtsük ki egy külön listába a pozitív számokat!
|
||||
|
||||
var pozitivak = szamok.FindAll(x=>x>=0);
|
||||
|
||||
foreach (var i in pozitivak)
|
||||
{
|
||||
Console.WriteLine(i);
|
||||
}
|
||||
|
||||
//Szerepel-e a listában 18?
|
||||
|
||||
if (szamok.Any(x=>x>=18 && x<=30))
|
||||
{
|
||||
Console.WriteLine("Van ilyen érték!");
|
||||
} else
|
||||
{
|
||||
Console.WriteLine("Nincs ilyen érték!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user