Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- namespace kartka6
- {
- // zadanie 4
- // a) zaimplementuj 3 indexery
- // b) pierwszy ktory bedzie przykrywal podstawowy indexer slownika, lecz nie pozwoli ustawic wartosci osobie niepełnoletniej
- // c ) drugi który wydobywa pierwsza znaleziona wartosc ubezpieczenia dla podanego w parametrze nazwiska
- // d) trzeci, ktory wydobedzie liste wszystkich ubezpieczonych osob na kwote wyzsza niz podana jako klucz (value) ?????
- class Program
- {
- static void Main(string[] args)
- {
- Person p1 = new Person("Jan", "Nowak", 30);
- Person p2 = new Person("Aleksandra", "Bar", 25);
- Person p3 = new Person("Staszek", "Lewandowski", 17);
- Insurance insurance1 = new Insurance(20, 60);
- Insurance insurance2 = new Insurance(10, 40);
- Insurance insurance3 = new Insurance(15, 50);
- Dic dic= new Dic();
- dic.Insert(p1, insurance1);
- dic.Insert(p2, insurance2);
- //dic[p3] = insurance3;
- var zm = dic["Bar"];
- Console.Write(zm.Number+" "+zm.Value);
- }
- }
- class Person
- {
- public string Name{get; set;}
- public string Surname{get; set;}
- public int Age{get; set;}
- public Person(string Name, string Surname, int Age)
- {
- this.Name = Name;
- this.Surname = Surname;
- this.Age = Age;
- }
- }
- class Insurance
- {
- public int Number{get; set;}
- public int Value{get; set;}
- public Insurance(int Number, int Value)
- {
- this.Number = Number;
- this.Value = Value;
- }
- }
- class Dic
- {
- private Dictionary<Person, Insurance> dictionary ;
- public Dic()
- {
- dictionary = new Dictionary<Person, Insurance>();
- }
- public void Insert(Person key, Insurance value)
- {
- dictionary.Add(key, value);
- }
- // b) pierwszy ktory bedzie przykrywal podstawowy indexer slownika, lecz nie pozwoli ustawic wartosci osobie niepełnoletniej
- public Insurance this[Person p]
- {
- set
- {
- if(p.Age >= 18)
- dictionary[p] = value;
- else
- Console.WriteLine("Osoba niepełnoletnia");
- }
- get
- {
- return dictionary[p];
- }
- }
- // c ) drugi który wydobywa pierwsza znaleziona wartosc ubezpieczenia dla podanego w parametrze nazwiska
- public Insurance this[string surname]
- {
- get
- {
- return dictionary.FirstOrDefault(x=>x.Key.Surname == surname).Value;
- }
- }
- // d) trzeci, ktory wydobedzie liste wszystkich ubezpieczonych osob na kwote wyzsza niz podana jako klucz (value)
- public List<Person> this[int kwota]
- {
- get
- {
- List<Person> perosnList = new List<Person>();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement