public TableCollectionSingleton Merge(TableCollectionSingleton col) { TableCollectionSingleton rez = new TableCollectionSingleton(); foreach (Table i in col.data) { foreach (Table j in this.data) { if (i == j) { rez.Add(i); } } } for (int i = 0; i < rez.data.Length; i++) { for (int j = i + 1; j < rez.data.Length; j++) { if (rez.data[i] == rez.data[j]) { rez.Delete(j); } } } return(rez); }
public static TableCollectionSingleton GetInstance(Table[] data) { if (instance == null) { instance = new TableCollectionSingleton(data); } return(instance); }
static void Main(string[] args) { Table t1 = new Table(10, 20, 30, 100, "T-1"); Table t2 = new Table(30, 20, 10, 80, "T-2"); t2.Depth = 3; TableInfo.GetInfo(t1); var anon = new { height = 40, width = 20, depth = 30, price = 300, model = "B-4" }; TableCollection col1 = new TableCollection(); col1.Add(t1); col1.Add(t2); Table[] m1 = new Table[2]; m1[0] = t1; m1[1] = t2; TableCollection col2 = new TableCollection(m1); Console.WriteLine($"Равны ли коллекции col1 и col2: {col1.Equals( col2 )}\nХеш col1: {col1.GetHashCode()}\nХеш col2: {col2.GetHashCode()}"); Table t3 = new Table(5, 15, 20, 40, "T-3"); Table t4 = new Table(35, 25, 20, 40, "T-4"); TableCollection col3 = new TableCollection(); col3.Add(t3); col3.Add(t1); col3.Add(t2); col3.Add(t1); //TableCollection mt1 = col1.Merge(col3); //TableCollection mt2 = col3.Merge(col1); //Console.WriteLine("///\n" + col3.ToString()); //Console.WriteLine(mt1.ToString()); //Console.WriteLine(mt2.ToString()); TableCollectionSingleton tcs1; tcs1 = TableCollectionSingleton.GetInstance(); tcs1.Add(t3); tcs1.Add(t2); tcs1.Add(t1); Console.WriteLine(TableCollectionSingleton.GetInstance().ToString()); TableCollectionSingleton tcs2 = TableCollectionSingleton.GetInstance(); tcs2.Delete(0); Console.WriteLine(TableCollectionSingleton.GetInstance().ToString()); Console.WriteLine(tcs1.ToString()); }
public override bool Equals(object obj) ///////// { if (obj == null) { return(false); } TableCollectionSingleton t2 = obj as TableCollectionSingleton; if ((t2 == null) || (this.data.Length != t2.data.Length)) { return(false); } // return (this.data == t2.data); for (int i = 0; i < t2.data.Length; i++) { if (this.data[i] != t2.data[i]) { return(false); } } return(true); }