public static _3zad <T> operator *(_3zad <T> set1, _3zad <T> set2) { _3zad <T> resultSet = new _3zad <T>(); if (set1.setOne.Count < set2.setOne.Count) { foreach (var item in set1.setOne) { if (set2.setOne.Contains(item)) { resultSet.setOne.Add(item); } } } else { foreach (var item in set2.setOne) { if (set1.setOne.Contains(item)) { resultSet.setOne.Add(item); } } } return(resultSet); }
public static _3zad <T> operator +(_3zad <T> set1, _3zad <T> set2) //обьеденить { _3zad <T> resultSet = new _3zad <T>(); _3zad <T> set3 = new _3zad <T>() { }; if (set1.setOne != null && set1.setOne.Count > 0) { set3.setOne.AddRange(set1.setOne); } if (set2.setOne != null && set2.setOne.Count > 0) { set3.setOne.AddRange(set2.setOne); } resultSet.setOne = set3.setOne.Distinct().ToList(); return(resultSet); }
static void Main(string[] args) { try { Set <int> set1 = new Set <int>(); Set <int> set2 = new Set <int>(); Set <int> set3 = new Set <int>(); Set <int> set4 = new Set <int>(); Set <float> flat = new Set <float>(); for (int i = 0; i < 15; i++) { set1.Push(i); set2.Push(i + 5); } set1.Delete(5); set1 += 51; set1 += 14; Console.Write("Set1: "); foreach (var quality in set1.setOne) { Console.Write(quality + " "); } Console.Write("\n"); Console.Write("Set2: "); foreach (var quality in set2.setOne) { Console.Write(quality + " "); } Console.Write("\n"); Console.Write("Union: "); set3 = set1 + set2; Console.Write("Intersection: "); set4 = set1 * set2; foreach (var quality in set3.setOne) { Console.Write(quality + " "); } Console.Write("\n"); foreach (var quality in set4.setOne) { Console.Write(quality + " "); } Console.Write("\n"); if (set1) { var x = 0; } var xtr = (int)set1; Console.Write("Quality elements: " + xtr + "\n"); Console.Write(SetExtansion.Comma("hello wold priv mir!") + "\n"); Console.Write(SetExtansion.Max(set1) + "\n"); Console.Write(SetExtansion.Min(set1) + "\n"); SetExtansion.RemoveRepetition(set1); MyType myType = new MyType() { xe = 678 }; _3zad <TransportVehicle> asdasd = new _3zad <TransportVehicle>(); } catch (Exception e) { Console.WriteLine(e); } finally { Console.WriteLine("Hello world"); } }