Advertisement
YORDAN2347

DictinaryCommands

Apr 20th, 2021
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _20._04._21
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var students = new Dictionary<string, double>();
  12.  
  13.             students.Add("Георги", 3.5);
  14.             students.Add("Стефан", 4.5);
  15.             students.Add("Петър", 5);
  16.             students.Add("Цветан", 3.25);
  17.             students.Add("Христо", 4.75);
  18.             students.Add("Йордан", 6);
  19.  
  20.             Console.WriteLine($"Dictionary size is: {students.Count}");
  21.  
  22.             Console.WriteLine($"Георги mark: {students["Георги"]:f2}");
  23.  
  24.             students.Remove("Цветан");
  25.             Console.WriteLine($"Цветан removed");
  26.  
  27.             bool isTrue = students.ContainsKey("Йордан");
  28.             Console.WriteLine($"Is contains Йордан: {isTrue}");
  29.  
  30.             foreach (var student in students)
  31.             {
  32.                 Console.WriteLine($"Student Name: {student.Key}, Student Grade: {student.Value}");
  33.             }
  34.  
  35.             students.Clear();
  36.             Console.WriteLine($"Is Contains anything: {students.Any()}");
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement