コード例 #1
0
 public void SumTestMethod()
 {
     Lecture.DelegateExample _newInstance = new DelegateExample();
     _newInstance.PerformCalculationVar = _newInstance.PerformSumMethod;
     Assert.AreEqual <int>(_newInstance.PerformSumMethod(0, int.MaxValue), _newInstance.PerformCalculationVar(0, int.MaxValue));
     Assert.AreEqual <int>(_newInstance.PerformSumMethod(int.MinValue, int.MaxValue), _newInstance.PerformCalculationVar(int.MinValue, int.MaxValue));
 }
コード例 #2
0
ファイル: DelegateExampleUnitTest.cs プロジェクト: pstosio/TP
 public void SumTestMethod()
 {
     Lecture.DelegateExample _newInstance = new DelegateExample();
       _newInstance.PerformCalculationVar = _newInstance.PerformSumMethod;
       Assert.AreEqual<int>(_newInstance.PerformSumMethod(0, int.MaxValue), _newInstance.PerformCalculationVar(0, int.MaxValue));
       Assert.AreEqual<int>(_newInstance.PerformSumMethod(int.MinValue, int.MaxValue), _newInstance.PerformCalculationVar(int.MinValue, int.MaxValue));
 }
コード例 #3
0
        public void Execute(DelegateExample type)
        {
            switch (type)
            {
            case DelegateExample.Basic:
                new Calculator().Execute();
                break;

            case DelegateExample.AnonymousMethodAndLambda:
                new AnonymousMethodAndLambda().Execute();
                break;

            case DelegateExample.BuiltInFunc:
                new BuiltInDelegates().Execute(BuiltInDelegateOption.FuncBasic);
                //new BuiltInDelegates ().Execute (BuiltInDelegateOption.FuncParameterized);
                break;

            case DelegateExample.BuiltInAction:
                new BuiltInDelegates().Execute(BuiltInDelegateOption.Action);
                break;

            case DelegateExample.BuiltInPredicate:
                new BuiltInDelegates().Execute(BuiltInDelegateOption.Predicate);
                break;

            case DelegateExample.ExpressionTree:
                break;
            }
        }
コード例 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            FirstWindow fw = new FirstWindow();

            // Subscribe Delegate
            this.DelegateValue += new DelegateExample(fw.TargetedDelegateFunction);
            fw.Show();
        }
コード例 #5
0
    // Use this for initialization
    void Start()
    {
        // instance of this delegate
        DelegateExample myDelegate = Bar;

        //myDelegate(5);
        Foobar(Bar);
    }
コード例 #6
0
        private void button2_Click(object sender, EventArgs e)
        {
            SecondWindow sw = new SecondWindow();

            // Subscribe Delegate
            this.DelegateValue += new DelegateExample(sw.TargetedDelegateFunction);
            sw.Show();
        }
コード例 #7
0
        private static void DelegateExample()
        {
            int             _number   = 5;
            int             _number2  = 0;
            DelegateExample delegate1 = new DelegateExample(_number);

            _number2 = delegate1.TheLuckyNumber();
            Console.WriteLine("Delegate 1 lucky number: " + _number2);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Danubius1st/Lessons
        static void DisplayBasics()
        {
            int test = -1;

            while (test != 0)
            {
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.Write("Basics - Enter exercise no: (1 to 6) ");
                string input = Console.ReadLine();

                Console.Clear();
                int.TryParse(input, out test);
                Console.ForegroundColor = ConsoleColor.Green;
                switch (test)
                {
                case 0:
                    break;

                case 1:
                    TypeCodeExample tc = new TypeCodeExample("ex. 1.1 - TypeCode Enumeration");
                    NullCoalescingOperatorExample nco = new NullCoalescingOperatorExample("ex. 1.2 - Null Coalescing Operator");
                    TestOperator    to  = new TestOperator("Ex. 1.3 - Test Operator", null);
                    FormatExample   fe  = new FormatExample("ex. 1.4 - Format");
                    DelegateExample del = new DelegateExample(); del.Example("ex. 1.5 - Delegates");
                    del.Example();
                    break;

                case 2:
                    DelegateExample del2 = new DelegateExample(); del2.ActionExample("ex. 2.1 - Actions / Delegates\n");
                    break;

                case 3:
                    DelegateExample del3 = new DelegateExample(); del3.AnonymousExample("ex.3.2 - Actions / Delegates - anonymous\n");
                    break;

                case 4:
                    DelegateExample del4 = new DelegateExample(); del4.LambdaExample("ex. 4.1 - Actions / Delegates - lambdas\n");
                    break;

                case 5:
                    ConstructorChain cc1 = new ConstructorChain("ex. 5.1 - Constructor Chain:");
                    ConstructorChain cc2 = new ConstructorChain();
                    break;

                case 6:
                    string s = "Hello Extension Methods";
                    int    i = s.WordCount();
                    Console.WriteLine($"\tex. 6.1 - Extension Methods: The text \"{s}\" has {i} words");
                    break;

                default:
                    Console.WriteLine("Not implemented!");
                    break;
                }
            }
        }
コード例 #9
0
        private void DelegateExample()
        {
            Response.Write("DelegateExample" + "<br />");
            var example = new DelegateExample();

            foreach (TeamDTO team in example.GetTeamsInEasternConference())
            {
                Response.Write(team.TeamName + "<br />");
            }
        }
コード例 #10
0
        void Start()
        {
            // Initializing of delegate
            // <delegate-type> <name> = <name-of-method>
            DelegateExample myDelegate = Bar;

            myDelegate.Invoke(5);

            // Use another class
            Foobar(Foo);
        }
コード例 #11
0
ファイル: DelegateExampleUnitTest.cs プロジェクト: pstosio/TP
 public void MulticastTestMethod()
 {
     Lecture.DelegateExample _newInstance = new DelegateExample();
       _newInstance.PerformCalculationVar = _newInstance.PerformSumMethod;
       //Multicast #1
       _newInstance.PerformCalculationVar = new DelegateExample.PerformCalculation(_newInstance.PerformSumMethod) + new DelegateExample.PerformCalculation(DelegateExample.PerformSubtractMethod);
       //Multicast #1
       _newInstance.PerformCalculationVar = new DelegateExample.PerformCalculation(PerformSumMethod);
       _newInstance.PerformCalculationVar += new DelegateExample.PerformCalculation(DelegateExample.PerformSubtractMethod);
       Assert.AreEqual<int>(-1, _newInstance.PerformCalculationMethod(1, 2));
 }
コード例 #12
0
ファイル: Program.cs プロジェクト: coreyderosa/CSharpDrills
        public static void Main()
        {
            DelegateExample ex1, ex2, ex3, ex4;

            ex1 = new DelegateExample(Derp1);
            ex2 = new DelegateExample(Derp2);
            ex3 = ex1 + ex2;       //this will show both functions below
            ex4 = ex1 + ex2 - ex1; //this will only show the Derp2 function
            ex3();
            ex4();
        }
コード例 #13
0
        public C09Delegate()
        {
            DelegateExample a  = Method;
            Delegate        a2 = a;

            DelegateExample b  = Method;
            ICloneable      b2 = b;

            DelegateExample c  = Method;
            ISerializable   c2 = c;
        }
コード例 #14
0
 public void MulticastTestMethod()
 {
     Lecture.DelegateExample _newInstance = new DelegateExample();
     _newInstance.PerformCalculationVar = _newInstance.PerformSumMethod;
     //Multicast #1
     _newInstance.PerformCalculationVar = new DelegateExample.PerformCalculation(_newInstance.PerformSumMethod) + new DelegateExample.PerformCalculation(DelegateExample.PerformSubtractMethod);
     //Multicast #1
     _newInstance.PerformCalculationVar  = new DelegateExample.PerformCalculation(PerformSumMethod);
     _newInstance.PerformCalculationVar += new DelegateExample.PerformCalculation(DelegateExample.PerformSubtractMethod);
     Assert.AreEqual <int>(-1, _newInstance.PerformCalculationMethod(1, 2));
 }
コード例 #15
0
        static void DelegeteInAction()
        {
            DelegateExample        delExE1 = Hello;     // reference
            DelegateExampleWithStr delExE2;             // null

            delExE2 = null;                             // null
            delExE1.Invoke();
            delExE2?.Invoke("Ping pong");               // nothing

            delExE2 = HelloUser;                        // reference
            delExE2?.Invoke("Batman");                  // write in console "Hello, Batman"
        }
コード例 #16
0
ファイル: Timer.cs プロジェクト: IliyanAtkov/TelerikAcademy
        public void Beggining(DelegateExample someMethod, int intervalInSeconds, int totalTime)
        {
            DateTime begin = DateTime.Now;
            DateTime end   = begin.AddSeconds(totalTime);

            while (begin <= end)
            {
                Console.WriteLine("Text will repeat a few seconds");
                Thread.Sleep(intervalInSeconds);
                begin = DateTime.Now;
            }
        }
コード例 #17
0
ファイル: Timer.cs プロジェクト: Producenta/TelerikAcademy
        public void Beggining(DelegateExample someMethod, int intervalInSeconds, int totalTime)
        {
            DateTime begin = DateTime.Now;
            DateTime end = begin.AddSeconds(totalTime);

            while (begin <= end)
            {
                Console.WriteLine("Text will repeat a few seconds");
                Thread.Sleep(intervalInSeconds);
                begin = DateTime.Now;

            }
        }
コード例 #18
0
        public void Activate_Code()
        {
            // Act
            DelegateExample          example1 = Hello;
            DelegateExampleWithParam example2 = null;
            DelegateExample          example3 = null;
            //DelegateExample example4 = HelloUser;  not allowed operation

            // Action
            var example1Exception = Record.Exception(() => example1.Invoke());
            var example2Exception = Record.Exception(() => example2?.Invoke("Ping pong"));

            // Assert
            Assert.Null(example1Exception);
            Assert.Null(example2Exception);
            Assert.Throws <NullReferenceException>(() => example3.Invoke());
        }
コード例 #19
0
    static void Main(string[] args)
    {
        new DelegateExample().Show();

        // 使用事件
        var delegateExample = new DelegateExample();

        // 事件只能出现在+=、-=左边
        //delegateExample.eventExample = null;

        delegateExample.eventExample += new DelegateExample().NoReturnNoParamMethod;
        delegateExample.eventExample += new DelegateExample().NoReturnNoParamMethod_1;

        delegateExample.RunEvent();


        Console.Read();
    }
コード例 #20
0
    public static void Examples()
    {
        ArraysSamples();
        DeclareArrays();
        ArrayOfArrays();
        InitializeArray();

        var weatherData = (Date : DateTime.Now, LowTemp : 5, HighTemp : 30);

        // <StringInterpolation>
        Console.WriteLine($"The low and high temperature on {weatherData.Date:MM-DD-YYYY}");
        Console.WriteLine($"    was {weatherData.LowTemp} and {weatherData.HighTemp}.");
        // Output (similar to):
        // The low and high temperature on 08-11-2020
        //     was 5 and 30.
        // </StringInterpolation>
        DelegateExample.Main();

        ReadAttributes();
    }
コード例 #21
0
        private void delegatesButton_Click(object sender, EventArgs e)
        {
            DelegateExample de = new DelegateExample();
            del             d  = de.addNumbers;

            Debug.WriteLine("Adding the 1st delegated method");
            Debug.WriteLine(d(3, 2));

            Debug.WriteLine("Adding a 2nd delegated method");
            d += de.substractNumbers;
            Debug.WriteLine(d(3, 2));

            Debug.WriteLine("Adding a 3rd delegated method");
            d += de.mutliplyNumbers;
            Debug.WriteLine(d(3, 2));

            Debug.WriteLine("Deleting substract delegated method");
            d -= de.substractNumbers;
            Debug.WriteLine(d(3, 2));
        }
コード例 #22
0
        public void TestDelegate()
        {
            //create an instance of delegate
            DelegateExample dex1 = new DelegateExample(Notify);

            dex1("Romesh");

            //OR simpler way to declare instance of delegate
            DelegateExample dex2 = Notify;

            dex2("Pradip");

            //OR instantiate delegate by using anonymous method
            DelegateExample dex3 = delegate(string nm) { Console.WriteLine("Notification received for: {0}", nm); };

            dex2("Manish");

            //OR instantiate delegate using lambda expression
            DelegateExample dex4 = nm => { Console.WriteLine("Notification received for: {0}", nm); };

            //OR DelegateExample dex4 = (nm) => { Console.WriteLine("Notification received for: {0}", nm); };
            dex2("Gurmeet");
        }
コード例 #23
0
ファイル: Example.cs プロジェクト: harrymurfi/unity-RTS
 void FooBar(DelegateExample dele)
 {
     dele(50);
 }
コード例 #24
0
 public void OverflowTestMethod()
 {
     Lecture.DelegateExample _newInstance = new DelegateExample();
     _newInstance.PerformCalculationVar = _newInstance.PerformSumMethod;
     int _result = _newInstance.PerformCalculationVar(int.MaxValue, int.MaxValue);
 }
コード例 #25
0
    //
    //     private void Start()
    //     {
    //         DelegateExample myDelegate = Foo;
    //
    //         myDelegate.Invoke(1);
    //         myDelegate(2); // shorthand
    //
    //         Foobar(myDelegate);
    //         Foobar(Foo);
    //         Foobar(Bar);
    //     }

    public static void  Foobar(DelegateExample customDelegate)
    {
        Debug.Log("FooBar: ");
        customDelegate(50);
    }
コード例 #26
0
ファイル: DelegateExampleUnitTest.cs プロジェクト: pstosio/TP
 public void AfterCreatioTest()
 {
     Lecture.DelegateExample _newInstance = new DelegateExample();
       Assert.IsNotNull(_newInstance.PerformCalculationVar);
 }
コード例 #27
0
        // delegate <return type> <delegate-name> <parameter list>

        static void Main(string[] args)
        {
            Derived devived = new Derived(10);

            StrReverse obj         = new StrReverse();
            string     inputstring = string.Empty;

            //emailModule emailModule = new emailModule();
            //emailModule.ConnectToExchangeServer();

            CSharpFeatures   cSharpFeatures = new CSharpFeatures();
            delegateExamples delegateExObj  = new delegateExamples();

            List <string> operationList = new List <string>();

            operationList.Add("1. Reverse the string.");
            operationList.Add("2. Find the given string is palindrome.");
            operationList.Add("3. Difference b/n Select() and SelectMany() and Select & Where");
            operationList.Add("4. Expression Bodied Methods");
            operationList.Add("5. Auto-Property Initializers");
            operationList.Add("6. Conditional Access Operator");
            operationList.Add("7. String Interpolation");
            operationList.Add("8. Delegates");
            operationList.Add("9. Get First Letters of a string");
            operationList.Add("10. Single, SingleOrDefault, First and FirstOrDefault");
            operationList.Add("11. Polymorphism");
            operationList.Add("12. Read Excel file");
            operationList.Add("13. EF-CodeFirst");
            operationList.Add("14. Oops - Abstract and Interface.");
            operationList.Add("15. Oops - Polymorphism.");
            operationList.Add("16. Oops - Polymorphism.");
            //Oops WhereSelect


            foreach (var operation in operationList)
            {
                Console.WriteLine(operation.ToString());
            }

            Console.WriteLine("Choose your Option --); ");

            int option = int.Parse(Console.ReadLine());

            switch (option)
            {
            case 1:
                Console.WriteLine("Enter the String to be reversed.");
                inputstring = Console.ReadLine();
                if (!string.IsNullOrWhiteSpace(inputstring))
                {
                    Console.WriteLine($"Reversed String : {obj.ReverseString(inputstring)}");
                }

                else
                {
                    Console.WriteLine("Please enter the String to be reversed.");
                }
                Console.ReadKey();
                break;

            case 2:
                Console.WriteLine("Enter the String to verify whether its palindrome.");
                inputstring = Console.ReadLine();
                if (!string.IsNullOrWhiteSpace(inputstring))
                {
                    string ouputString = obj.ReverseString(inputstring);

                    if (ouputString == inputstring)
                    {
                        Console.WriteLine($"The string : {inputstring} is Palindrome.");
                    }
                    else
                    {
                        Console.WriteLine($"The string : {inputstring} is not Palindrome.");
                    }
                }
                else
                {
                    Console.WriteLine("Please enter the String to be reversed.");
                }
                Console.ReadKey();
                break;

            case 3:
                LinqQ linq = new LinqQ();
                linq.CheckMissingNumber();
                linq.WhereSelect();
                linq.CheckSelectAndSelectMany();
                Console.ReadKey();
                break;

            case 4:
                Console.WriteLine("Enter Employee Id to Find.");
                inputstring = Console.ReadLine();
                var skills = cSharpFeatures.GetSkillByEmployeeId(Convert.ToInt32(inputstring));
                Console.WriteLine($"Skills for Employee Id {Convert.ToInt32(inputstring)} is {string.Join(",", skills)} ");
                Console.ReadKey();
                Main(null);
                break;

            case 5:
                var lastName = cSharpFeatures.LastName;
                Console.WriteLine($"Auto-Property Initializer value for LastName {lastName} ");
                Console.ReadKey();
                Main(null);
                break;

            case 6:
                Console.WriteLine("Enter Employee Id to Find.");
                inputstring = Console.ReadLine();
                var employeeName = cSharpFeatures.GetEmployeeNameById(Convert.ToInt32(inputstring));
                Console.WriteLine($"Conditional Access Operator {employeeName} ");
                Console.ReadKey();
                Main(null);
                break;

            case 7:
                var fullName = cSharpFeatures.GetFullName();
                Console.WriteLine($"String-Interpolation {fullName} ");
                Console.ReadKey();
                Main(null);
                break;

            case 8:
                DelegateExample delegateEx = delegateExObj.SumValue;
                var             sum        = delegateEx(2);
                Console.WriteLine($"Sum On Delegate : {Convert.ToString(sum)}");
                DelegateExample delegateEx1 = new DelegateExample(delegateExObj.Muliply);
                var             multiply    = delegateEx1(10);
                Console.WriteLine($"Sum On Delegate : {Convert.ToString(multiply)}");

                Console.ReadKey();
                Main(null);
                break;

            case 9:
                var firstLetters = cSharpFeatures.GetFirstLetters();
                Console.WriteLine($"First Letters:- {firstLetters} ");
                Console.ReadKey();
                Main(null);
                break;

            case 10:
                obj.SingleSingleOrDefaultFirstFirstOrDefault();
                Console.ReadKey();
                Main(null);
                break;

            case 11:
                Polymorphism polymorphism = new Polymorphism();
                polymorphism.Area(20);
                Console.WriteLine("Polymorphism-Area-Two Parameters - {0}", polymorphism.Area(20, 30));
                Console.ReadKey();
                Main(null);
                break;

            case 12:
                TestClass testClass = new TestClass();
                testClass.GetExcelData();
                Console.WriteLine("Polymorphism-Area-Two Parameters - {0}", 1);
                Console.ReadKey();
                Main(null);
                break;

            case 13:
                EFCodeFirst efCodeFirst = new EFCodeFirst();
                efCodeFirst.InsertData();
                break;

            case 14:
                AbstractInterface abstractInterface = new AbstractInterface();
                abstractInterface.NonAbstarctFun();
                abstractInterface.AbstractFun();
                abstractInterface.InterfaceFun1();
                Console.ReadKey();
                Main(null);
                break;

            case 15:
                DapperClass dapperClass = new DapperClass();
                Console.WriteLine($"Command Text : Employee Ids : {dapperClass.GetEmployeeIdTextCommand()}");
                Console.WriteLine($"SP : Employee Ids : {dapperClass.GetEmployeeIdSP()}");
                //Console.WriteLine(dapperClass.InsertDepartmentSP());
                //Console.WriteLine(dapperClass.InsertEmployeeSP());
                //Console.WriteLine(dapperClass.InsertDepartmentComText());
                Console.WriteLine(dapperClass.InsertEmployeeComText());
                dapperClass.GetEmployees();
                Console.ReadKey();
                Main(null);
                break;

            default:
                Console.WriteLine("Default case");
                Console.ReadKey();
                break;
            }
        }
コード例 #28
0
 void Foobar(DelegateExample myDelegate)
 {
     myDelegate(50);
 }
コード例 #29
0
        public static void Main()
        {
            DelegateExample ex = new DelegateExample(Derp);

            ex("Delegates are confusing");
        }
コード例 #30
0
ファイル: Program.cs プロジェクト: siwy4430/StartupRepository
 public Program()
 {
     this.Przyklad = new DelegateExample(Mnozenie);
     this.Example = new Funkcja<int, int>(Multiplication);
 }
コード例 #31
0
 public void AfterCreatioTest()
 {
     Lecture.DelegateExample _newInstance = new DelegateExample();
     Assert.IsNotNull(_newInstance.PerformCalculationVar);
 }
コード例 #32
0
ファイル: Program.cs プロジェクト: mirusser/Learning-dontNet
 private static void Main(string[] args)
 {
     DelegateExample.Run();
     EventExample.Run();
     MoreRealisticExample.Run();
 }
コード例 #33
0
ファイル: Timer.cs プロジェクト: etcet1/TelerikAcademy
 static void Main()
 {
     DelegateExample timer = new DelegateExample(TimerInstance);
     timer("This delegate is running at every 2 seconds", 2);
 }
コード例 #34
0
 public static void AddDelegate(DelegateExample customDelegate)
 {
     _Delegate1 += customDelegate;
 }
コード例 #35
0
ファイル: DelegateExampleUnitTest.cs プロジェクト: pstosio/TP
 public void OverflowTestMethod()
 {
     Lecture.DelegateExample _newInstance = new DelegateExample();
       _newInstance.PerformCalculationVar = _newInstance.PerformSumMethod;
       int _result = _newInstance.PerformCalculationVar(int.MaxValue, int.MaxValue);
 }