Advertisement
kasper_k

task1oop

Jan 17th, 2023 (edited)
1,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TasksOOP
  8. {
  9.     class Weather: ICloneable
  10.     {
  11.         private string city;
  12.         private int temperature;
  13.         private DateTime data = new DateTime();    
  14.         public string City { get => city; }
  15.         public int Temperature { get => temperature; set => temperature = value; }
  16.         public DateTime Data { get => data; set => data = value; }
  17.         public Weather(string city, int temperature, DateTime dateTime)
  18.         {
  19.             City = city;
  20.             Temperature = Converse(temperature);
  21.             Data = dateTime;
  22.         }
  23.         public int Converse(int t)
  24.         {
  25.             return t * (9 / 5) + 32;
  26.         }
  27.         public object Clone()
  28.         {
  29.             //return new Weather(City, Temperature, Data);
  30.             return MemberwiseClone();
  31.         }
  32.     }
  33.     class Program
  34.     {
  35.         static void Main(string[] args)
  36.         {
  37.             List<Weather> weathers = new List<Weather>();
  38.             Weather weather1 = new Weather("Nurlat", 37, new DateTime(2023, 01, 17));
  39.             Weather weather2 = new Weather("Kazan", 10, new DateTime(2023, 03, 15));
  40.             Weather weather3 = new Weather("Nurlat", -78, new DateTime(2023, 05, 27));
  41.             weathers.Add(weather1);
  42.             weathers.Add(weather2);
  43.             weathers.Add(weather3);
  44.             var linqweathers = weathers.GroupBy(c => c.Data);
  45.             foreach (var weathers1 in linqweathers)
  46.             {
  47.                 foreach (var item in weathers1)
  48.                 {
  49.                     Console.WriteLine($"{item.City} \t {item.Temperature} \t {item.Data}");
  50.                 }
  51.             }
  52.             Console.ReadKey();
  53.         }
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement