Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6.  
  7. namespace kartka6
  8. {
  9. // zadanie 1
  10. // a) metoda która bedzie moliwa do wywolania bez tworzenia obiektu
  11. // b) przyjmuję zmienną liczbę słownikow na wzór słownika polsko-angielskiego
  12. // c) zwraca slownik będący polączeniem wszystkich słownikówprzekazanych do metody
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             f1("lala");
  18.             Dictionary<string, string> dic = new Dictionary<string, string>();
  19.             dic.Add("Cat", "kot");
  20.             dic.Add("Dog", "pies");
  21.  
  22.             Dictionary<string, string> dic2 = new Dictionary<string, string>();
  23.             dic2.Add("House", "dom");
  24.             dic2.Add("Garden", "ogród");
  25.  
  26.             f2(dic, dic2);
  27.  
  28.             var newDic1 = f3(dic,dic2);
  29.             foreach(KeyValuePair<string, string> zm in newDic1)
  30.             {
  31.                    Console.WriteLine("Key = {0}, Value = {1}", zm.Key, zm.Value);
  32.             }
  33.         }
  34.  
  35.         public static void f1(string s)
  36.         {
  37.             Console.WriteLine("Text: "+s);
  38.         }
  39.  
  40.         public static void f2(params Dictionary<string, string> [] dic)
  41.         {
  42.             for(int i=0; i< dic.Length; i++)
  43.             {
  44.                  foreach(KeyValuePair<string, string> zm in dic[i])
  45.                 {
  46.                     Console.WriteLine("Key = {0}, Value = {1}", zm.Key, zm.Value);
  47.                 }
  48.             }
  49.         }
  50.  
  51.          public static Dictionary<string, string> f3(params Dictionary<string, string> [] dic)
  52.         {
  53.             Dictionary<string, string> newDic = new Dictionary<string, string>();
  54.             for(int i=0; i< dic.Length; i++)
  55.             {
  56.                  foreach(KeyValuePair<string, string> zm in dic[i])
  57.                 {
  58.                     newDic.Add(zm.Key, zm.Value);
  59.                 }
  60.             }
  61.  
  62.             return newDic;
  63.         }
  64.     }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement