Advertisement
AIwinter

2 lab oop

Dec 2nd, 2022
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4.  
  5. namespace ConsoleApp6
  6. {
  7.     internal class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var FavoriteFood = new string[] { "Apple", "Cake", "Pizza", "Salad" };
  12.  
  13.             //поиск наиб числа среди целых чисел в arraylist
  14.             //алгоритм: определять тип, то чето с ним делать
  15.             // if p из тип - тру или фолс
  16.             // cast преобразования: перед переменной (тип)
  17.  
  18.             Console.WriteLine("\n 2) ArrayList: ");
  19.             ArrayList pos = new() { -1f, -2f, -3f, -5f, -6f, -11f};
  20.  
  21.             pos.AddRange(FavoriteFood);
  22.             pos.Remove("Apple");
  23.             pos.Remove("Salad");
  24.  
  25.             float max = float.MinValue;
  26.  
  27.             foreach (var p in pos)
  28.             {
  29.                 if (p is float)
  30.                 {
  31.                     if ((float)p > max)
  32.                     {
  33.                         max = (float)p;
  34.                     }
  35.                 }
  36.             }
  37.             Console.Write(max);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement