public void TestDelegates() { StaticTesting staticTesting = new StaticTesting(); //clasic way to assign a new delegate // pointToMethod myDelegate = new pointToMethod(StaticTesting.PrintName); //compiler does work behind the scene as the above example //pointToMethod myDelegate = StaticTesting.PrintName; //can add multiple methods to the delegates' invocation list //myDelegate += StaticTesting.PrintName; //myDelegate("Alex"); //pointToMethod myDelegate = StaticTesting.ReturnStaticStringTwo; //myDelegate += StaticTesting.ReturnStaticStringOne; //string localString = myDelegate(); //Console.WriteLine(myDelegate()); //pointToDog myDogDelegate = this.GetDoge; //pointToAnimal myAnimalDelegate = this.doVet; //CountIt myCountDelegate = TestCounting; //myCountDelegate(); //or with anonymous founction //CountIt myAnonymousDelegate = delegate //{ // for (int i = 0; i < 5; i++) // { // Console.WriteLine(i); // } //}; //myAnonymousDelegate(); //AddIt myLambdaDelegate = (int x) => x + 5; //statement lambda //expression lambda AddIt myLambdaDelegate = (int x) => { for (int i = 0; i < 5; i++) { Console.WriteLine(i); } Console.WriteLine("Lambda loop ended"); return(x + 5); }; int result = myLambdaDelegate(5); Console.WriteLine(result); Console.ReadKey(); }
public void AdditionTest() { AddIt testAdd = new AddIt(); ArrayList myNums = new ArrayList(); myNums.Add(5); myNums.Add(5); int answer = testAdd.Addition(myNums); Assert.AreEqual(answer, 10); }
static void Main(string[] args) { var a = new AddIt() { "hello", "world" }; Console.Read(); }
public string Calculate(string input) { // creates a new RegexProcessor RegexUtil regexProcessing = new RegexUtil(); // creates a new setting ConstantParser ConstantParser constantSetting = new ConstantParser(); // extract integers ArrayList integers = regexProcessing.ExtractNums(input); // extracts operand string thisOp = regexProcessing.ExtractsOp(input); // holds answer value string answer; // make a new instance of the applicable class per the // operand extracted switch (thisOp) { case "+": AddIt thisAddExp = new AddIt(); answer = thisAddExp.Addition(integers).ToString(); LastQnA.LastAns = Convert.ToInt32(answer); LastQnA.LastQ = input; return answer; case "-": SubtractIt thisSubExp = new SubtractIt(); answer = thisSubExp.Subtraction(integers).ToString(); LastQnA.LastAns = Convert.ToInt32(answer); LastQnA.LastQ = input; return answer; case "*": MultiplyIt thisMultiExp = new MultiplyIt(); answer = thisMultiExp.Multiplication(integers).ToString(); LastQnA.LastAns = Convert.ToInt32(answer); LastQnA.LastQ = input; return answer; case "/": DivideIt thisDivExp = new DivideIt(); answer = thisDivExp.Division(integers).ToString(); LastQnA.LastAns = Convert.ToInt32(answer); LastQnA.LastQ = input; return answer; case "%": ModIt thisModExp = new ModIt(); answer = thisModExp.Modulation(integers).ToString(); LastQnA.LastAns = Convert.ToInt32(answer); LastQnA.LastQ = input; return answer; case "=": answer = "Your value has been set"; return answer; default: throw new ArgumentException("Input doesn't contain an operand understood {0}", thisOp); } }
// this is going to extract which type of expression it is public string ExtractsOp(string input) { Match AddMatch = add_regex.Match(input); Match DivideMatch = divide_regex.Match(input); Match MultiMatch = multiply_regex.Match(input); Match SubMatch = subt_regex.Match(input); Match ModMatch = mod_regex.Match(input); if (AddMatch.Success) { AddIt thisAdd = new AddIt(); return "+"; } else if (SubMatch.Success) { SubtractIt thisSub = new SubtractIt(); return "-"; } else if (MultiMatch.Success) { MultiplyIt thisMult = new MultiplyIt(); return "*"; } else if (DivideMatch.Success) { DivideIt thisDiv = new DivideIt(); return "/"; } else if (ModMatch.Success) { ModIt thisMod = new ModIt(); return "%"; } else { throw new ArgumentException("No operator provided"); } }
// Start is called before the first frame update void Start() { c1 = FindObjectOfType <AddIt>(); Posi = this.transform.position; }