From f1c3921b08bb22ac6f5db22d620e01d7e8e5c49f Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期一, 30 十二月 2019 13:32:33 +0800
Subject: [PATCH] 2019-12-30-1

---
 ZigbeeApp/GateWay.Ios/Main.cs |  180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 180 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/GateWay.Ios/Main.cs b/ZigbeeApp/GateWay.Ios/Main.cs
new file mode 100755
index 0000000..6f3c497
--- /dev/null
+++ b/ZigbeeApp/GateWay.Ios/Main.cs
@@ -0,0 +1,180 @@
+锘縰sing System;
+using System.Collections.Generic;
+using UIKit;
+
+namespace GateWay.Ios
+{
+    public class Application
+    {
+        // This is the main entry point of the application.
+        static void Main(string[] args)
+        {
+            // if you want to use a different Application Delegate class from "AppDelegate"
+            // you can specify it here.
+            UIApplication.Main(args, null, "AppDelegate");
+
+            //Study P246
+            int x = 40;
+            GetAString firstStringMethod = new GetAString(x.ToString);
+            GetAString firstStringMethod1 = x.ToString;
+
+            var balance = new Currency(34, 50);
+            firstStringMethod1 = balance.ToString;
+            firstStringMethod1 = new GetAString(Currency.GetCurrencyUnit);
+
+            #region 绠�鍗曠殑濮旀墭
+
+
+            DoubleOp[] operations =
+            {
+                MathOperation .MultiplyByTwo ,
+                MathOperation.Square
+            };
+
+            for (int i = 0; i < operations.Length; i++)
+            {
+                // System.Console.WriteLine($ "Using operations[{i}]:);
+                var aa = $"{operations[i]}";
+                ProcessAndDisplayNumber(operations[i], 2.0);
+                ProcessAndDisplayNumber(operations[i], 7.9);
+                ProcessAndDisplayNumber(operations[i], 21.4);
+            }
+
+            #region 鍐掓场鎺掑簭
+            int[] sortArray = { 0, 5, 6, 2, 1 };
+            bool swapped = true;
+            do
+            {
+                swapped = false;
+                for (int i = 0; i < sortArray.Length - 1; i++)
+                {
+                    if (sortArray[i] > sortArray[i + 1])
+                    {
+                        int temp = sortArray[i];
+                        sortArray[i] = sortArray[i + 1];
+                        sortArray[i - 1] = temp;
+                        swapped = true;
+                    }
+                }
+            } while (swapped);
+
+
+            //绗簩绉嶆柟娉�
+            Employee[] employees =
+            {
+                new Employee ("A",20000),
+                new Employee ("B",30000),
+                new Employee ("C",40000),
+            };
+
+            BubbleSorter.Sort(employees, Employee.CompareSalary);
+            foreach (var employee in employees )
+            {
+                var aa = employee;
+            }
+            #endregion  
+        }
+
+
+
+        static void ProcessAndDisplayNumber1(Func<double, double> action, double value)
+        {
+            double result = action(value);
+        }
+
+        //浣跨敤Fun<in T,out TResult>鏉ヤ唬鏇胯嚜瀹氫箟鐨凞oubleOp锛�
+        //        <double, double>[] operations1 = 
+        //        {
+        //            MathOperation.MultiplyByTwo ,
+        //            MathOperation.Square
+        //};
+
+        static void ProcessAndDisplayNumber(DoubleOp action, double value)
+        {
+            double result = action(value);
+        }
+
+        class MathOperation
+        {
+            public static double MultiplyByTwo(double value) => value * 2;
+            public static double Square(double value) => value * value;
+        }
+
+        delegate double DoubleOp(double x);
+        #endregion 
+
+        private delegate string GetAString();
+
+        struct Currency
+        {
+            public uint Dollers;
+            public ushort Cents;
+
+            public Currency(uint dollers, ushort cents)
+            {
+                this.Dollers = dollers;
+                this.Cents = cents;
+            }
+
+            public override string ToString() => $"${Dollers}.{Cents,2:00}";
+            public static string GetCurrencyUnit() => "Dollers";
+            public static explicit operator Currency(float value)
+            {
+                checked
+                {
+                    uint dollers = (uint)value;
+                    ushort cents = (ushort)((value - dollers) + 100);
+                    return new Currency(dollers, cents);
+                }
+            }
+
+            public static implicit operator float(Currency value) =>
+            value.Dollers + (value.Cents / 100.0f);
+
+            public static implicit operator Currency(uint value) =>
+            new Currency(value, 0);
+
+            public static implicit operator uint(Currency value) =>
+            value.Dollers;
+        }
+
+        class BubbleSorter
+        {
+            static public void Sort<T>(IList<T> sortArray, Func<T, T, bool> comparison)
+            {
+                bool swapped = true;
+                do
+                {
+                    swapped = false;
+                    for (int i = 0; i < sortArray.Count - 1;i++){
+                        if(comparison (sortArray [i+1],sortArray [i]))
+                        {
+                            T temp = sortArray[i];
+                            sortArray[i] = sortArray[i + 1];
+                            sortArray[i + 1] = temp;
+                            swapped = true;
+                        }
+                    }
+
+                } while (swapped);
+            }
+        }
+
+        class Employee
+        {
+            public Employee (string name,decimal  salary)
+            {
+                Name = name;
+                Salary = Salary;
+            }
+
+            public string Name { get; }
+            public Decimal Salary { get; private set; }
+
+            public override string ToString() => $"{Name},{Salary:C}";
+            public static bool CompareSalary(Employee e1, Employee e2) => e1.Salary < e2.Salary;
+		}
+
+    }
+}
+

--
Gitblit v1.8.0