using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Memory_understanding { class Reapting_elements { public void getfirstrepeatingelements(int[] arr) { int min = -1; int element=0; HashSet<int> set = new HashSet<int>(); for (int i = arr.Length-1; i >= 0; i--) { if(set.Contains(arr[i])) { min=i; element=arr[i]; ...
Understading Callback method wher a function is executed not on the main thread but on a child thread that it created . Similary there are different ways of executing function created on the child thread. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Memory_understanding { public delegate void sumofnumberscallback(int sumofnumber); class A { int target; public A(int num) { this.target= num; } public void printNumber(int n) { ...
Factory Design Pattern In Factory pattern, we create object without exposing the creation logic. In this pattern, an interface is used for creating an object, but let subclass decide which class to instantiate. The creation of object is done when it is required. The Factory method allows a class later instantiation to subclasses. Template: interface Product { } class ConcreteProductA : Product { } class ConcreteProductB : Product { } abstract class Creator { public abstract Product FactoryMethod(string type); } class ConcreteCreator : Creator { public override Product FactoryMethod(string type) { switch (type) { case "A": return new ConcreteProductA(); case "B": return new ConcreteProductB(); default: throw new ArgumentException("Invalid type", "type"); } } } using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // Liskov Substitution Principle ...
Comments
Post a Comment