dmitryEfremov

DZ/29/07

Jul 27th, 2025
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.44 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using System.Globalization;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net.NetworkInformation;
  10. using System.Runtime.InteropServices;
  11. using System.Runtime.InteropServices.ComTypes;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using Microsoft.SqlServer.Server;
  15.  
  16. namespace ConsoleApp1
  17. {
  18.     internal class Program
  19.     {
  20.         static void Main(string[] args)
  21.         {
  22.             Temperature temperature = new Temperature();
  23.             temperature.Celsius = -300;
  24.             Console.WriteLine("Celsius: " + temperature.Celsius);
  25.             temperature.Celsius = -273;
  26.             Console.WriteLine("Celsius: " + temperature.Celsius);
  27.  
  28.             Console.WriteLine("Counter: " + Counter.InstanceCount);
  29.             new Counter();
  30.             Console.WriteLine("Counter: " + Counter.InstanceCount);
  31.             new Counter();
  32.             Console.WriteLine("Counter: " + Counter.InstanceCount);
  33.  
  34.             StringList stringList = new StringList(10);
  35.             stringList[0] = "1";
  36.             stringList[1] = "2";
  37.             Console.WriteLine("stringList:" + stringList);
  38.             Console.WriteLine("stringList[0]:" + stringList[0]);
  39.  
  40.             var calculateResult = Calculate(5, 6);
  41.             Console.WriteLine($"X:{calculateResult.x} Y:{calculateResult.y} Distance:{calculateResult.distance}");
  42.  
  43.             List<Employee> employees = new List<Employee>();
  44.             employees.Add(new Employee("Вася", 5));
  45.             employees.Add(new Employee("Лёша", 3));
  46.             employees.Add(new Employee("Гена", 10));
  47.  
  48.             GetResume(employees).ToList().ForEach(resume => Console.WriteLine($"Id:[{resume.Item1}] Name:[{resume.Item2}] ExpYears:[{resume.Item3}]"));
  49.  
  50.             var eventList = new[]
  51.             {
  52.                 new{ EventName = "ШП", Date = 3 },
  53.                 new{ EventName = "День рождение", Date = 50},
  54.                 new{ EventName = "Новый год", Date = 158}
  55.             };
  56.             eventList.ToList().ForEach(eventItem => Console.WriteLine($"Событие:{eventItem.EventName}, Кол-во дней до события:{eventItem.Date}"));
  57.  
  58.             var listStatistics = new List<(string ProductName, int Sold, double Price)>();
  59.             listStatistics.Add(("Молоко", 5, 50));
  60.             listStatistics.Add(("Снежок", 15, 60));
  61.             // как спроецировать на IEnumerable не понятно
  62.         }
  63.  
  64.         static (int x, int y, double distance) Calculate(int x, int y)
  65.         {
  66.             return ( x, y, Math.Sqrt(x * x + y * y));
  67.         }
  68.  
  69.         static IEnumerable<ValueTuple<int,string,int>> GetResume(List<Employee> employees)
  70.         {
  71.             return employees.Select(emp => ValueTuple.Create(emp.Id, emp.Name, emp.ExperienceYears));
  72.         }
  73.     }
  74.  
  75.     internal class Employee
  76.     {
  77.         private static int _id;
  78.  
  79.         public int Id;
  80.         public string Name;
  81.         public int ExperienceYears;
  82.  
  83.         public Employee(string name, int experienceYears)
  84.         {
  85.             _id++;
  86.             Id = _id;
  87.             Name = name;
  88.             ExperienceYears = experienceYears;
  89.         }
  90.     }
  91.  
  92.     public class Temperature
  93.     {
  94.         private float _celsius;
  95.         public float Celsius
  96.         {
  97.             get { return _celsius; }
  98.             set
  99.             {
  100.                 if (value >= -273.15f)
  101.                 {
  102.                     _celsius = value;
  103.                 }
  104.             }
  105.         }
  106.     }
  107.  
  108.     public class Counter
  109.     {
  110.         public static int InstanceCount { get; private set; }
  111.  
  112.         public Counter()
  113.         {
  114.             InstanceCount++;
  115.         }
  116.  
  117.     }
  118.  
  119.     public class StringList
  120.     {
  121.         private List<string> list;
  122.        
  123.         public StringList(int count)
  124.         {
  125.             list = new List<string>();
  126.             for (int i = 0; i < count; i++)
  127.             {
  128.                 list.Add("");
  129.             }
  130.         }
  131.  
  132.         public String this[int index]
  133.         {
  134.             get { return list[index]; }
  135.             set
  136.             {
  137.                 if(index >= 0 && index <= list.Count)
  138.                 list[index] = value;
  139.             }
  140.         }
  141.  
  142.         public override string ToString()
  143.         {
  144.             return string.Join(", ", list);
  145.         }
  146.     }
  147. }
  148.  
Advertisement
Add Comment
Please, Sign In to add comment