Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine(PerformOperation(Calculator.Add, 4, 6));
            Console.WriteLine(PerformOperation(Calculator.Subtract, 4, 6));
            string input = Console.ReadLine();
            int    i     = System.Convert.ToInt32(input);

            Delegate1 d1 = null;

            if (i == 0)
            {
                d1 = Display;
            }
            else
            {
                d1 = Display4;
            }
            d1.Invoke();
            d1();
            //Delegate2 d2 = new Delegate2(Display2);
            Delegate2 d2 = Display2;

            d2("AOA Pakistan...");

            Delegate3 d3 = Display3;
            string    s  = d3("Some text");
        }
Ejemplo n.º 2
0
        public void SafeSetText(ToolStripLabel toolStripLabel, string text)
        {
            Delegate1 delegate2 = null;

            if (base.InvokeRequired)
            {
                if (delegate2 == null)
                {
                    delegate2 = new Delegate1(this.method_1);
                }
                Delegate1 method = delegate2;
                try
                {
                    base.Invoke(method, new object[] { toolStripLabel, text });
                }
                catch
                {
                }
            }
            else
            {
                foreach (ToolStripItem item in base.Items)
                {
                    if (item == toolStripLabel)
                    {
                        item.Text = text;
                    }
                }
            }
        }
Ejemplo n.º 3
0
    private void cmdBuiltInCallback_Click(object sender, System.EventArgs e)
    {
        //Delegates have a built-in mechanism to call back into the client. The
        //method to be called back into must have a specific signature, however.
        //This method will use the built-in callback of an asynchronous invocation
        //on a delegate, and will call into the BuiltInCallback method below this one.
        //Note that no user registration is needed.
        Class1 refClass1 = new Class1();

        //Create an instance of a delegate to represent the callback method
        Delegate1 d = new Delegate1(refClass1.UseBuiltInDelegateCallback);

        //Now create a second delegate to pass to the callee. The callee will use
        //This second delegate to call back into the client. AsyncCallback is
        //defined in the CLR specifically for calling back after an asynchronous
        //invocation of a delegate.
        AsyncCallback ac = new AsyncCallback(this.BuiltInCallback);

        //Invoke the class one method. Note that this invocation is asynchronous,
        //and will be carried out on a worker thread from the CLR thread pool. The
        //resulting callback will also be performed by the worker thread. The
        //callback delegate is passed in as an argument, so no explicit registration
        //is needed.
        d.BeginInvoke(ac, null);
    }
Ejemplo n.º 4
0
 // Token: 0x060006BC RID: 1724 RVA: 0x0002C2A8 File Offset: 0x0002A4A8
 public static void smethod_9(Assembly assembly_1)
 {
     if (!Class59.bool_0)
     {
         object obj = Class59.object_0;
         lock (obj)
         {
             if (!Class59.bool_0)
             {
                 Class59.smethod_1(assembly_1);
                 Type       type        = assembly_1.GetType("Microsoft.FSharp.Reflection.FSharpType");
                 MethodInfo methodBase_ = Class59.smethod_10(type, "IsUnion", BindingFlags.Static | BindingFlags.Public);
                 Class59.IsUnion = Class124.smethod_19().vmethod_0 <object>(methodBase_);
                 MethodInfo methodBase_2 = Class59.smethod_10(type, "GetUnionCases", BindingFlags.Static | BindingFlags.Public);
                 Class59.GetUnionCases = Class124.smethod_19().vmethod_0 <object>(methodBase_2);
                 Type type2 = assembly_1.GetType("Microsoft.FSharp.Reflection.FSharpValue");
                 Class59.PreComputeUnionTagReader   = Class59.smethod_11(type2, "PreComputeUnionTagReader");
                 Class59.PreComputeUnionReader      = Class59.smethod_11(type2, "PreComputeUnionReader");
                 Class59.PreComputeUnionConstructor = Class59.smethod_11(type2, "PreComputeUnionConstructor");
                 Type type3 = assembly_1.GetType("Microsoft.FSharp.Reflection.UnionCaseInfo");
                 Class59.smethod_5(Class124.smethod_19().vmethod_3 <object>(type3.GetProperty("Name")));
                 Class59.smethod_7(Class124.smethod_19().vmethod_3 <object>(type3.GetProperty("Tag")));
                 Class59.smethod_3(Class124.smethod_19().vmethod_3 <object>(type3.GetProperty("DeclaringType")));
                 Class59.smethod_8(Class124.smethod_19().vmethod_0 <object>(type3.GetMethod("GetFields")));
                 Class59.methodInfo_0 = assembly_1.GetType("Microsoft.FSharp.Collections.ListModule").GetMethod("OfSeq");
                 Class59.kXkxeOrhTr   = assembly_1.GetType("Microsoft.FSharp.Collections.FSharpMap`2");
                 Thread.MemoryBarrier();
                 Class59.bool_0 = true;
             }
         }
     }
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            double p1 = -12.44;
            float  p2 = -14.3f;
            int    p3 = 200;

            Console.WriteLine($"Допустим: p1= {p1} p2= {p2} p3= {p3}");
            PosFun("Все ли числа положительны? ", p1, p2, p3, AllPositive_YorN);
            PosFun("Положительно ли произведение? ", p1, p2, p3, CompositionPos_YorN);

            Delegate1 dg1 = (double x, float y, int z) =>// проверим на положительность сумму
            {
                if (x + y + z > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            };
            bool test = dg1(1.1, -12, -12);

            PosFun("Пример с лямбда-выражения в виде переменной: ", p1, p2, p3, dg1);
            Console.WriteLine($"test= {test}");
        }
Ejemplo n.º 6
0
		protected void Dispatcher_BeginInvoke_InvalidateRequerySuggested()
		{
			if (invalidateRequerySuggestedDelegate == null)
				invalidateRequerySuggestedDelegate = new Delegate1(CommandManager.InvalidateRequerySuggested);

			Dispatcher.BeginInvoke(invalidateRequerySuggestedDelegate, null);
		}
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Delegate1 delegate1 = new Delegate1(Method1);
            Delegate2 delegate2 = delegate1();

            delegate2();
        }
Ejemplo n.º 8
0
 // Token: 0x060006A6 RID: 1702 RVA: 0x000073F0 File Offset: 0x000055F0
 public Class58(object object_1, Delegate1 <object, object> delegate1_1)
 {
     Class202.ofdixO4zTbIfy();
     base..ctor();
     this.object_0    = object_1;
     this.delegate1_0 = delegate1_1;
 }
 public void method()
 {
     if (Event1 != null)
     {
         Event1 += new Delegate1(method1);
         Event1 -= new Delegate1(method1);
         Event1();
     }
     if (Event2 != null)
     {
         Event2 += new Delegate1(method1);
         Event2 -= new Delegate1(method1);
         Event2();
     }
     if (Event3 != null)
     {
         Event3 += new Delegate1(method1);
         Event3 -= new Delegate1(method1);
         Event3();
     }
     if (Event4 != null)
     {
         Event4 += new Delegate1(method1);
         Event4 -= new Delegate1(method1);
         Event4();
     }
 }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            var d = new Delegate(() => { });

            Delegate1 d1 = delegate() { };
            Delegate2 d2 = delegate(string s) { };
            Delegate3 d3 = delegate() { return(string.Empty); };
            Delegate4 d4 = delegate(string s) { return(s); };
            Delegate5 d5 = delegate(string s, int x)
            {
                var xs = x.ToString();
                return($"{s}{xs}");
            };

            Delegate1 dl1 = () => { };
            //Delegate2 dl2 = (string s) => { };
            //Delegate2 dl2 = (s) => { };
            Delegate2 dl2 = s => { };
            //Delegate3 dl3 = () => { return string.Empty; };
            Delegate3 dl3 = () => string.Empty;
            Delegate4 dl4 = s => s;
            Delegate5 dl5 = (s, x) =>
            {
                var xs = x.ToString();
                return($"{s}{xs}");
            };


            var odd = Enumerable.Range(0, 100).Where(i => i % 2 == 1);

            int[] array = Enumerable.Range(0, 100).ToArray();

            var myOdd  = array.Filter(i => i % 2 == 1);
            var myEven = array.Filter(i => i % 2 == 0);
        }
        public void Main()
        {
            Delegate1 d1     = AddNums1;
            double    result = d1(10, 20, 30);

            Console.WriteLine(result);
            //or
            Func <int, float, double, double> obj1 = AddNums1;

            result = obj1(11, 22, 33);
            Console.WriteLine(result);

            Delegate2 d2 = AddNums2;

            d2(20, 30, 40);
            //or
            Action <int, float, double> obj2 = AddNums2;

            obj2(22, 33, 44);


            Delegate3 d3   = CheckLenght;
            bool      flag = d3("Navjyot");

            Console.WriteLine(flag);
            //or
            Predicate <string> obj3 = CheckLenght;

            obj3("Navjyot");
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            //Instatinating the delaegate
            Delegate1 obj1 = new Delegate1(Isodd);//passing method here

            Console.WriteLine(obj1(2));
            Console.ReadKey();
        }
Ejemplo n.º 13
0
        static void method(Delegate1 d, Delegate2 e, System.Delegate f)
        {
            //컴파일 에러
            //Console.WriteLine(d==e);

            //
            System.Console.WriteLine(d == f);
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            Delegate1 del1 = () => "Hello", del2 = () => "World";
            Delegate3 del3 = () => del1() + ", " + del2() + "!";

            Console.WriteLine(del3());
            Console.ReadKey();
        }
Ejemplo n.º 15
0
        // Comparing delegates of two different types assigned at compile-time will result in a compilation error. If the delegate
        // instances are statically of the type System.Delegate, then the comparison is allowed, but will return false at run time.
        static void method(Delegate1 d, Delegate2 e, System.Delegate f)
        {
            // Compile-time error.
            //Console.WriteLine(d == e);

            // OK at compile-time. False if the run-time type of f
            // is not the same as that of d.
            Console.WriteLine(d == f);
        }
    static public int Main(String[] args)
    {
        Test <string> b = new Test <string> ();
        int           res;

        Console.WriteLine("Test1...");
        b.test();
        Console.WriteLine("Test2...");
        Test <string> .test_static();

        Console.WriteLine("Test3...");
        try
        {
            b.test_exception();
        }
        catch (SynchronizationLockException ex)
        {
            return(1);
        }
        catch (Exception ex)
        {
            // OK
        }

        Console.WriteLine("Test4...");
        b.test_virtual();

        Console.WriteLine("Test5...");
        Delegate1 d = new Delegate1(b.test);

        res = d();

        Console.WriteLine("Test6...");
        d   = new Delegate1(Test <string> .test_static);
        res = d();

        Console.WriteLine("Test7...");
        d   = new Delegate1(b.test_virtual);
        res = d();

        Console.WriteLine("Test8...");
        d = new Delegate1(b.test_exception);
        try
        {
            d();
        }
        catch (SynchronizationLockException ex)
        {
            return(2);
        }
        catch (Exception ex)
        {
            // OK
        }

        return(0);
    }
Ejemplo n.º 17
0
 static void MinMetode(int a, int b, Delegate1 done)
 {
     // gør noget med a og b
     //done.Invoke();
     if (done != null)
     {
         done.Invoke();
     }
 }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            string    input  = Console.ReadLine();
            Delegate1 myDel1 = () => Method1; // Использована техника предположения делегата
            Delegate2 myDel2 = myDel1();

            myDel2(input);
            Console.ReadKey();
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            Delegate1 my   = new Delegate1(Method1);
            Delegate2 math = my();

            Console.WriteLine(math(5));
            Console.WriteLine();
            Console.ReadKey();
        }
 public void method()
 {
     if (Event != null)
     {
         Event += new Delegate1(method1);
         Event -= new Delegate1(method1);
         Event();
     }
 }
Ejemplo n.º 21
0
    //private delegate int OnjSum(int i, int j); // 1. 선언
    public static void Main(string[] args)
    {
        Func <int, int, int> myMethod = new Delegate1().Sum; // new 생략가능

        // 미리 선언된 델리게이터 Func, Action
        // <파라미터형, 가장 오른쪽에 리턴자료형>

        Console.WriteLine("두수 합 : {0}", myMethod(10, 30));
    }
Ejemplo n.º 22
0
        static void Main()
        {
            Demo1     obj = new Demo1();
            Delegate1 d1  = new Delegate1(obj.M1);

            obj.M2(d1);
            obj.M2(obj.M1);
            Console.ReadKey();
        }
Ejemplo n.º 23
0
 public void method()
 {
     if (Event != null)
     {
         Event += new Delegate1(method1);
         Event -= new Delegate1(method1);
         Event();
     }
 }
Ejemplo n.º 24
0
        public void Invoke1()
        {
            Delegate1 del1 = new Delegate1(Helper.WorkPerformed1);
            Delegate1 del2 = new Delegate1(Helper.WorkPerformed2);
            Delegate1 del3 = new Delegate1(Helper.WorkPerformed3);

            del1 += del2 + del3;

            del1(10, WorkType.GenerateReports);
        }
Ejemplo n.º 25
0
        public static void Run()
        {
            Delegate1 deleg1 = FooDelegate;
            Delegate2 deleg2 = FooDelegate;

            //deleg2 = deleg1;

            RunDelegatsArgContvar();
            RunDelegatsReturnCovar();
        }
Ejemplo n.º 26
0
        public Form1()
        {
            InitializeComponent();
            port              = new SerialPort();
            port.ReadTimeout  = 500;
            port.WriteTimeout = 500;

            Opcje.Enter       += new EventHandler(Opcje_Enter);
            port.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
            my_del1            = new Delegate1(ReadReceived);
        }
Ejemplo n.º 27
0
        static void Main()
        {
            Delegate1 delegate1 = new Delegate1(Method1);

            Delegate2 delegate2 = delegate1();

            delegate2();

            // Delay.
            Console.ReadKey();
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Метод рассчитывает значения функции делегата f на интервале от x до b
        /// </summary>
        /// <param name="f">Функция Делегат</param>
        /// <param name="x">Начало интервала</param>
        /// <param name="b">Конец интервала</param>
        /// <returns>Массив значений функции</returns>
        public double[] FunData(Delegate1 f, double x, double b)
        {
            List <double> result = new List <double>();

            while (x <= b)
            {
                result.Add(f(x));
                x++;
            }
            return(result.ToArray());
        }
Ejemplo n.º 29
0
 // Token: 0x06002F78 RID: 12152
 // RVA: 0x00133A58 File Offset: 0x00131C58
 internal void method_2(Delegate1 delegate1_1)
 {
     Delegate1 delegate = this.delegate1_0;
     Delegate1 delegate2;
     do
     {
         delegate2 = delegate;
         Delegate1 value = (Delegate1)Delegate.Combine(delegate2, delegate1_1);
         delegate = Interlocked.CompareExchange<Delegate1>(ref this.delegate1_0, value, delegate2);
     }
     while (delegate != delegate2);
 }
        static void Main(string[] args)
        {
            int num = 22869;

            int[] arr = new int[] { 69, 96, 14, 88, 11, 22, 33, 44, 56, 66 };

            Delegate1 del1 = new Delegate1(Class1.FormArray);
            Delegate2 del2 = new Delegate2(Class1.DisplayArray);

            del2(del1(num));
            del2(arr);
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            Delegate1 obj = AddNums1;
            double result = obj.Invoke(10, 20.5f, 50.2);
            Console.WriteLine(result);
            Delegate2 obj2 = AddNums2;
            obj2.Invoke(10, 55.2f,12.5);
           //
            Console.Read();


        }
Ejemplo n.º 32
0
        static void Main(string[] args)
        {
            var delegateInstance1 = new Delegate1(Method01);

            delegateInstance1();
            Delegate1 delegateInstance2 = Method01;

            delegateInstance2();
            Action delegateInstance3 = Method01;

            Delegate2 delegateInstance4 = (x) => { return((int)Math.Pow(x, 3)); };
            Delegate2 delegateInstance5 = x => (int)Math.Pow(x, 3);
        }
Ejemplo n.º 33
0
        static void Main(string[] args)
        {
            Delegate1 d1 = new Delegate1(Method1);
            Delegate2 d2 = d1();

            d2();

            Functional func = new Functional(MethodF);

            D3 d3 = func.Invoke(new D1(M1), new D2(M2));

            Console.WriteLine(d3.Invoke());
        }
Ejemplo n.º 34
0
        static void Main(string[] args)
        {
            int d1 = 20, d2 = 10;

            Delegate1 Dvar = new Delegate1(TriA);

            Console.WriteLine("1.三角形");
            GetArea(d1, d2, Dvar);

            Console.WriteLine("2.矩形");
            GetArea(d1, d2, new Delegate1(RecA));

            Console.Read();
        }
    public static int Main(String[] args)
    {
        Test b = new Test ();
        int res;

        Console.WriteLine ("Test1...");
        b.test ();
        Console.WriteLine ("Test2...");
        test_static ();
        Console.WriteLine ("Test3...");
        try {
            b.test_exception ();
        }
        catch (SynchronizationLockException ex) {
            return 1;
        }
        catch (Exception ex) {
            // OK
        }

        Console.WriteLine ("Test4...");
        b.test_virtual ();

        Console.WriteLine ("Test5...");
        Delegate1 d = new Delegate1 (b.test);
        res = d ();

        Console.WriteLine ("Test6...");
        d = new Delegate1 (test_static);
        res = d ();

        Console.WriteLine ("Test7...");
        d = new Delegate1 (b.test_virtual);
        res = d ();

        Console.WriteLine ("Test8...");
        d = new Delegate1 (b.test_exception);
        try {
            d ();
        }
        catch (SynchronizationLockException ex) {
            return 2;
        }
        catch (Exception ex) {
            // OK
        }

        return 0;
    }
Ejemplo n.º 36
0
 public void method()
 {
     if (Event1 != null)
     {
         Event1 += new Delegate1(method1);
         Event1();
     }
     if (Event2 != null)
     {
         Event2 += new Delegate1(method1);
         Event2();
     }
     if (Event3 != null)
     {
         Event3 += new Delegate1(method1);
         Event3();
     }
 }
 public void Method1(Delegate1 x, Delegate2 y)
 {
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Print number of symbols
 /// </summary>
 /// <param name="del">Delegat-method</param>
 /// <param name="mess">message to count</param>
 private static void ShowNum(Delegate1 del, string mess)
 {
     Console.WriteLine(del(mess));
 }
Ejemplo n.º 39
0
	static public int Main (String[] args) {
		Tests b = new Tests ();
		int res, err;

		Console.WriteLine ("Test1...");
		b.test ();
		if (is_synchronized (b))
			return 1;

		Console.WriteLine ("Test2...");
		test_static ();
		if (is_synchronized (typeof (Tests)))
			return 1;

		Console.WriteLine ("Test3...");
		try {
			b.test_exception ();
		}
		catch (SynchronizationLockException ex) {
			return 1;
		}
		catch (Exception ex) {
			// OK
		}
		if (is_synchronized (b))
			return 1;

		Console.WriteLine ("Test4...");
		b.test_virtual ();
		if (is_synchronized (b))
			return 1;

		Console.WriteLine ("Test5...");
		Delegate1 d = new Delegate1 (b.test);
		res = d ();
		if (is_synchronized (b))
			return 1;

		Console.WriteLine ("Test6...");
		d = new Delegate1 (test_static);
		res = d ();
		if (is_synchronized (typeof (Tests)))
			return 1;

		Console.WriteLine ("Test7...");
		d = new Delegate1 (b.test_virtual);
		res = d ();
		if (is_synchronized (b))
			return 1;

		Console.WriteLine ("Test8...");
		d = new Delegate1 (b.test_exception);
		try {
			d ();
		}
		catch (SynchronizationLockException ex) {
			return 2;
		}
		catch (Exception ex) {
			// OK
		}
		if (is_synchronized (b))
			return 1;

		return 0;
	}
Ejemplo n.º 40
0
 private void Packetlogger_Load(object sender, EventArgs e)
 {
     this.fontDialog_0.Font = this.richTextBox1.Font;
     Class1.bool_0 = Class1.bool_1 = false;
     this.delegate1_1 = new Delegate1(this.method_1);
     this.delegate1_0 = new Delegate1(this.method_0);
     this.color_0 = Color.PaleGreen;
     this.color_1 = Color.MediumPurple;
 }
Ejemplo n.º 41
0
    public static void loadFromFile(Delegate1 action)
    {
        string _path = Application.persistentDataPath + "/initial.conf";
        Debug.Log (_path);
        io = new IO ();
        if (File.Exists (_path)) {
            //Leemos el archivo. los datos estan separados por #
            string data = io.Read (Application.persistentDataPath + "/initial.conf");
            string [] datos = data.Split ('#');
            ip = datos [0];
            //expresion regular ip
            Match match = Regex.Match(ip, @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}");
            if (!match.Success)
            {
                tag=null;
            }
            //checa si es numerico el puerto
            port = datos [1];
            int n;
            if(!int.TryParse(port, out n)){
                tag=null;
            }
            tag = datos [2];
            long_tag = "/"+tag;
            string [] tag_data = tag.Split ('/');
            //checa que la ruta sea no mayor a dos

            if(tag_data.Length==2){
                tag = tag_data [1];
            }else{
                tag=null;
            }
            color.a=1.0f;
            //checa que la cadena tag sea acorde a secciones validas
            switch (tag){
                case DecodeQuestions.CO2:
                    //toma color verde para tipografia
                    color = new Color(69.0f/255.0f, 183.0f/255.0f, 114.0f/255.0f);
                    //numero de maximo de elementos que existen para mandar al MURAL
                    wall_elements=6;
                break;
                case DecodeQuestions.H2O:
                    //toma color azul para tipografia
                    color = new Color(15.0f/255.0f, 168.0f/255.0f, 209.0f/255.0f);
                    //numero de maximo de elementos que existen para mandar al MURAL
                    wall_elements=4;
                break;
                case DecodeQuestions.RESIDUOS:
                    //toma color anaranjado para tipografia
                    color = new Color(252.0f/255.0f, 151.0f/255.0f, 52.0f/255.0f);
                    //numero de maximo de elementos que existen para mandar al MURAL
                    wall_elements=3;
                break;
                default:
                    tag=null;
                break;
            }

            action ();
        } else {
            tag=null;
            action();
        }
    }
Ejemplo n.º 42
0
 public static Delegate3 MethodF(Delegate1 delegate1, Delegate2 delegate2)
 {
     return delegate { return delegate1.Invoke() + delegate2.Invoke(); };
 }