Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TasksOOP
- {
- class Weather: ICloneable
- {
- private string city;
- private int temperature;
- private DateTime data = new DateTime();
- public string City { get => city; }
- public int Temperature { get => temperature; set => temperature = value; }
- public DateTime Data { get => data; set => data = value; }
- public Weather(string city, int temperature, DateTime dateTime)
- {
- City = city;
- Temperature = Converse(temperature);
- Data = dateTime;
- }
- public int Converse(int t)
- {
- return t * (9 / 5) + 32;
- }
- public object Clone()
- {
- //return new Weather(City, Temperature, Data);
- return MemberwiseClone();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Weather> weathers = new List<Weather>();
- Weather weather1 = new Weather("Nurlat", 37, new DateTime(2023, 01, 17));
- Weather weather2 = new Weather("Kazan", 10, new DateTime(2023, 03, 15));
- Weather weather3 = new Weather("Nurlat", -78, new DateTime(2023, 05, 27));
- weathers.Add(weather1);
- weathers.Add(weather2);
- weathers.Add(weather3);
- var linqweathers = weathers.GroupBy(c => c.Data);
- foreach (var weathers1 in linqweathers)
- {
- foreach (var item in weathers1)
- {
- Console.WriteLine($"{item.City} \t {item.Temperature} \t {item.Data}");
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement