Uebungsaufgaben_ITFA_2_SS_2025/Exercises/E22_Dictionary/Exercise_4.cs
2025-03-10 15:59:34 +01:00

30 lines
689 B
C#

using System;
using System.IO;
using Microsoft.VisualBasic;
namespace Exercises_C_Sharp.E22_Dictionary
{
class Exercise_4
{
//Addieren Sie alle Value-Werte mit geraden Index auf und geben Sie das Ergebnis aus.
public static void Start()
{
Dictionary<int, double> dic = new() {{1, 14.85}, {2, 58.52}, {3, 8.63}, {4, 6.49}, {5, 62.85}, {6, 2.22}, {7, 3.33}, {8, 9.99}};
//Code Start
double add = 0;
foreach(var element in dic)
if(element.Key % 2 == 0)
add += element.Value;
Console.WriteLine("Ergebnis: " + add);
//Code ENDE
}
}
}