(四)WPF./C#常用的例子集合

//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace test
//{
//    class Program
//    {
//        static int a3 = 3;
//        static public int A3
//        {
//            get { return a3; }
//            set { a3 = value; }
//        }

//        static int a4 = 44;
//        static public int A4
//        {
//            get { return a4; }
//            set
//            {
//                if (value > 10)
//                {
//                    a4 = 20;
//                }
//                else if (value < 10)
//                {
//                    a4 = 5555555;
//                }
//            }
//        }
//        static void Main(string[] args)
//        {
//            Console.WriteLine(a3);
//            Console.WriteLine(A3);
//            Console.WriteLine();

//            A3 = 22;
//            Console.WriteLine(a3);
//            Console.WriteLine(A3);

//            Console.WriteLine();
//            Console.WriteLine(a4);
//            Console.WriteLine(A4);
//            A4 = 21;
//            Console.WriteLine(a4);
//            Console.WriteLine(A4);
//            Console.ReadLine();
//        }
//    }
//}



//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace test
//{
//    class Program
//    {
//        static int a1;
//        static string str1;
//        static void Main(string[] args)
//        {
//            int a2 = 2;
//            Console.WriteLine(a1);
//            Console.WriteLine(a2);
//            string str2 = "字符串2";
//            Console.WriteLine(str1);
//            Console.WriteLine(str2);
//            //MethodA();
//            Console.WriteLine(a3);
//            Console.WriteLine(a4);
//            //static a3 = 33;
//            Console.ReadLine();
//        }
//        public void MethodA()
//        {
//            a1 = 3;
//            //a2 = 22;
//            int a3 = 3;
//            static int a4 = 4;
//            Console.WriteLine(a4);
//            Console.WriteLine(a1);
//        }
//    }
//}
#region 整数转字符串
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            //整数转字符串
//            int a = 33;
//            string str_a = Convert.ToString(a);
//            Console.WriteLine(Convert.ToString(str_a));

//            //字符串转整数
//            string str = "444";
//            int i_str = Convert.ToInt32(str);
//            Console.WriteLine(i_str);


//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region 字节转字符串
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {

//            byte[] bytPassword = new byte[4] { 56, 56, 56, 56 };
//            //byte[]转成string:
//            string str = System.Text.Encoding.Default.GetString(bytPassword);
//            Console.ReadLine();
//        }
//    }
//}
#endregion

//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            //int iContextFlagLong = 2;
//            //int iContextByteLong = 259;
//            //byte[] byt_iContextByteLong = new byte[iContextFlagLong];//用来表示内容的长度,2B字节保存。
//            //byt_iContextByteLong = BitConverter.GetBytes(iContextByteLong);

//            //字符长度字节 1 Byte
//            int iContextFlagLong = 2;
//            int iContextByteLong;
//            byte[] byt_StrContextLong = new byte[4];//用来表示内容的长度,2B字节保存。
//            byte[] byt_StrContextLongVar = new byte[4];
//            iContextByteLong = 259;
//            byt_StrContextLongVar = BitConverter.GetBytes(iContextByteLong);
//            byt_StrContextLong[0] = byt_StrContextLongVar[0];//低八位
//            byt_StrContextLong[1] = byt_StrContextLongVar[1];//高八位

//            //将字符长度字节与内容字节合并
//            List<byte> listButter = new List<byte>();
//            byte[] byt_SumProtocolByteLong = new byte[1] { 23 };
//            listButter.AddRange(byt_StrContextLong);
//            listButter.AddRange(byt_SumProtocolByteLong);

//            int iProtocolCount = System.BitConverter.ToInt32(byt_StrContextLong, 0);
//        }
//    }
//}

//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {

//            string fileDir = Environment.CurrentDirectory;
//            Console.WriteLine("当前程序目录:" + fileDir);
//            Console.ReadLine();
//        }
//    }
//}


#region 消息队列
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Messaging;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;

//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            #region 创建消息队列  
//            const string queueName = @".\Private$\jiyiqin";
//            MessageQueue mq = null;
//            if (!MessageQueue.Exists(queueName))// 如果指定的路径queueName中不存在队列,那么在该路径,即queueName中创建一个消息队列。jiyiqin就是你想要创建消息队列的名字
//            {
//                mq = MessageQueue.Create(queueName);//创建名称jiyiqin的消息队列的实例。
//                Console.WriteLine("创建消息队列完成:" + queueName);
//            }
//            else  //如果消息队列jiyiqin已经存在,那么创建该消息队列的一个实例
//            {
//                mq = new MessageQueue(queueName);//创建名称jiyiqin的消息队列的实例。
//            }
//            mq.SetPermissions("Administrator", MessageQueueAccessRights.FullControl);
//            mq.SetPermissions("ANONYMOUS LOGON", MessageQueueAccessRights.FullControl);
//            mq.SetPermissions("Everyone", MessageQueueAccessRights.FullControl);
//            #endregion

//            #region 发送消息队列
//            string strTx = "123我";
//            Message msgTx = new Message();
//            msgTx.Body = strTx;
//            msgTx.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
//            mq.Send(msgTx);
//            #endregion

//            #region 接收消息队列
//            //接收到的消息对象
//            Message msgRx = mq.Receive();
//            //指定格式化程序
//            msgRx.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
//            //接收到的内容
//            string strRx = msgRx.Body.ToString();
//            System.Windows.Forms.MessageBox.Show(strRx);
//            #endregion


//            创建第二个消息队列
//            //const string queueName2 = @".\Private$\jiyiqin2";
//            //MessageQueue mq2 = null;
//            //if (!MessageQueue.Exists(queueName2))// 如果指定的路径queueName中不存在队列,那么在该路径,即queueName中创建一个消息队列。jiyiqin就是你想要创建消息队列的名字
//            //{
//            //    mq2 = MessageQueue.Create(queueName2);//创建名称jiyiqin的消息队列的实例。
//            //    Console.WriteLine("创建消息队列完成:" + queueName2);
//            //}
//            //else  //如果消息队列jiyiqin已经存在,那么创建该消息队列的一个实例
//            //{
//            //    mq2 = new MessageQueue(queueName2);//创建名称jiyiqin的消息队列的实例。
//            //}
//            //mq2.SetPermissions("Administrator", MessageQueueAccessRights.FullControl);
//            //mq2.SetPermissions("ANONYMOUS LOGON", MessageQueueAccessRights.FullControl);
//            //mq2.SetPermissions("Everyone", MessageQueueAccessRights.FullControl);

//            接收第一个消息队列
//            接收到的消息对象
//            //Message msgRx2 = mq.Receive();
//            指定格式化程序
//            //msgRx2.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
//            接收到的内容
//            //string strRx2 = msgRx2.Body.ToString();
//            //System.Windows.Forms.MessageBox.Show(strRx2);

//        }
//    }
//}
#endregion


#region 文件的读写
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;

//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            #region 读文本文件
//            //1、常规的读法
//            string str1 = File.ReadAllText(@"C:\Users\lanmage2\Desktop\新建文本文档.txt");
//            Console.WriteLine(str1);
//            //2、编码方式的读法 
//            string str2 = File.ReadAllText(@"C:\Users\lanmage2\Desktop\新建文本文档.txt", Encoding.ASCII);
//            string str3 = File.ReadAllText(@"C:\Users\lanmage2\Desktop\新建文本文档.txt", Encoding.Default);//Default才能正确读写中午
//            Console.WriteLine(str2);
//            Console.WriteLine(str3);
//            Console.ReadLine();
//            #endregion
//        }
//    }
//}
#endregion

#region XML配置文件 IP
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;

//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            //将XML文件加载进来
//            string strFilePath;
//            strFilePath = Environment.CurrentDirectory + "\\IPconfig.xml";
//            XDocument document = XDocument.Load(strFilePath);
//            //获取到XML的根元素进行操作
//            XElement root = document.Root;//根节点(即第一个节点)
//            XElement ip = root.Element("IP");//获取根节点的第二个节点
//            //获取name标签的值
//            XElement ipValue = ip.Element("IPValue");//获取IP节点的元素,即第三个节点
//            Console.WriteLine(ipValue.Value);
//            //获取根元素下的所有子元素
//            IEnumerable<XElement> enumerable = root.Elements();
//            foreach (XElement item in enumerable)
//            {
//                foreach (XElement item1 in item.Elements())
//                {
//                    Console.WriteLine(item1.Name);   //输出 name  name1            
//                }
//                Console.WriteLine(item.Attribute("id").Value);  //输出20
//            }
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region 单实例类
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;

//namespace test
//{
//    class Program
//    {

//        static void Main(string[] args)
//        {
//            //方法1:中间类ClassB调用了单实例类Singleton,通过实例化中间类ClassB。
//            ClassB classb = new ClassB();
//            classb.methodB();


//            //方法2:直接实例化Singleton。
//            Singleton singleton = Singleton.GetInstance();
//            Console.WriteLine(singleton.iGlobalNum1);

//            //方法3:调用方法GetSingleton()来实例化Singleton。
//            GetSingleton();
//            Console.ReadLine();
//        }

//        static private void GetSingleton()
//        {
//            Singleton singleton = Singleton.GetInstance();
//            Console.WriteLine(singleton.bGlobalStatus1);
//        }
//    }
//}
#endregion

#region (一)连接数据库:基本入门
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//using System.Configuration;  //ConfigurationManager类的命名空间
using System.Data.SqlClient; //SqlConnection类的命名空间
//using System.Data.Common;    //DbProviderFactory、DbProviderFactories、DbConnection、DbCommand、DbDataReader的命名空间


//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            Console.WriteLine("重要的事情说三遍:我要准备开始连接数据了,各位。然后打印一张数据表到控制台给大家look look ");
//            Console.WriteLine("重要的事情说三遍:我要准备开始连接数据了,各位。然后打印一张数据表到控制台给大家look look ");
//            Console.WriteLine("重要的事情说三遍:我要准备开始连接数据了,各位。然后打印一张数据表到控制台给大家look look ");

//            #region  *******步骤1:加载配置文件*******
//            //数据提供者:实际上就是要连接SQLServer数据库
//            string strDataProvider = ConfigurationManager.AppSettings["provider"];

//            /*连接SQLServer数据库的名字*/
//            //方法1:连接App.config的appSettring节点
//            string strConnectStr = ConfigurationManager.AppSettings["cnStr"];
//            //方法2:连接App.config的ConnectionStrings节点的数据库
//            string strConnectStr2 = ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString;
//            #endregion

//            #region *******步骤2:创建数据提供搬运工厂的对象*******
//            //数据搬运的中介,将数据库的数据搬运到C#主程序,所以它有一个专业的名字叫:数据提供程序工厂
//            DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory(strDataProvider);
//            #endregion

//            #region *******步骤3:连接对象*******
//            //创建连接对象
//            using (DbConnection dbConnection = dbProviderFactory.CreateConnection())
//            {
//                //配置连接对象
//                dbConnection.ConnectionString = strConnectStr;//方法2:strConnectStr2
//                //打开连接对象
//                dbConnection.Open();
//                #endregion

//                #region *******步骤4:命令对象*******
//                //创建命令对象
//                DbCommand dbCommand = dbProviderFactory.CreateCommand();
//                Console.WriteLine("dbCommand.GetType().Name = " + dbCommand.GetType().Name);
//                //配置命令对象
//                dbCommand.Connection = dbConnection;                  //命令对象需要连接的实体。
//                dbCommand.CommandText = "Select * From Inventory";    //命令对象运行的文本指令(即SQL语句)
//                #endregion

//                #region *******步骤5:数据读取器对象*******
//                //创建数据读取器对象
//                using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
//                {
//                    Console.WriteLine("dbDataReader.GetType().Name = " + dbDataReader.GetType().Name);
//                    while (dbDataReader.Read())
//                    {
//                        //Console.WriteLine("输出当前汽车数据表Inventory的汽车ID及其品牌");
//                        Console.WriteLine("CarID = {0}, Make = {1}", dbDataReader["CarID"], dbDataReader["Make"].ToString());
//                    }
//                }
//                #endregion
//            }
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region (二)连接数据库:更加详细解释 System.Data.SqlClient每个对象类的使用方法。
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
using System.Configuration;  //ConfigurationManager类的命名空间
//using System.Data.SqlClient; //SqlConnection类、SqlCommand类、SqlDataReader类的命名空间
using System.Data.Common;    //DbProviderFactory、DbProviderFactories、DbConnection、DbCommand、DbDataReader的命名空间


//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            Console.WriteLine("重要的事情说三遍:我要准备开始连接数据了,各位。然后打印一张数据表到控制台给大家look look ");
//            Console.WriteLine("重要的事情说三遍:我要准备开始连接数据了,各位。然后打印一张数据表到控制台给大家look look ");
//            Console.WriteLine("重要的事情说三遍:我要准备开始连接数据了,各位。然后打印一张数据表到控制台给大家look look ");
//            Console.WriteLine();
//            //创建连接对象并打开
//            using (SqlConnection sqlConnection = new SqlConnection())
//            {

//                sqlConnection.ConnectionString = @"Data Source = (localdb)\MSSQLLocalDB; Integrated Security = SSPI; Initial Catalog = E:\PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL14.MSSQLSERVER\MSSQL\DATA\MYSQL_LIBRARY\AUTOLOT.MDF";
//                sqlConnection.Open();
//                //显示连接状态
//                ShowConnectionStatus(sqlConnection);
//                Console.WriteLine();

//                //连接对象附加上了命令对象(即SQL语句)
//                string strSQL = "Select * From Inventory; select * from Customers";
//                SqlCommand myCommand = new SqlCommand(strSQL, sqlConnection);

//                //数据读写器
//                using (SqlDataReader sqlDataReader = myCommand.ExecuteReader())
//                {
//                    do
//                    {
//                        while (sqlDataReader.Read())//循环输出当前表的每列
//                        {
//                            for (int i = 0; i < sqlDataReader.FieldCount; i++)//sqlDataReader.FieldCount表示当前表的列数
//                            {
//                                Console.WriteLine(sqlDataReader.GetName(i) + " = " + sqlDataReader.GetValue(i));
//                            }
//                        }
//                        Console.WriteLine();
//                    }
//                    while (sqlDataReader.NextResult());//循环输出多个表。我这里输出表Inventory,和表Customers
//                }
//            }
//            Console.ReadLine();
//        }

//        /// <summary>
//        /// 显示连接对象的各种状态
//        /// </summary>
//        /// <param name="sqlConnectionVar"></param>
//        static void ShowConnectionStatus(SqlConnection sqlConnectionVar)
//        {
//            Console.WriteLine("sqlConnectionVar.DataSource        = {0}", sqlConnectionVar.DataSource);
//            Console.WriteLine("sqlConnectionVar.Database          = {0}", sqlConnectionVar.Database);
//            Console.WriteLine("sqlConnectionVar.ConnectionTimeout = {0}", sqlConnectionVar.ConnectionTimeout);
//            Console.WriteLine("sqlConnectionVar.State.ToString()  = {0}", sqlConnectionVar.State.ToString());
//        }
//    }
//}
#endregion

#region object类的应用举例1。
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//namespace test
//{
//    class Program
//    {

//        enum Colors
//        {
//            red,
//            green
//        }
//        static void Main(string[] args)
//        {
//            // Construct a Point object.
//            Point p1 = new Point(1, 2);

//            // Make another Point object that is a copy of the first.
//            Point p2 = p1.Copy();

//            // Make another variable that references the first Point object.
//            Point p3 = p1;

//            // The line below displays false because p1 and p2 refer to two different objects.
//            Console.WriteLine(Object.ReferenceEquals(p1, p2));//ReferenceEquals表示比较对象。而p1、p2是不同的object,所以输出结果为false

//            // The line below displays true because p1 and p2 refer to two different objects that have the same value.
//            Console.WriteLine(Object.Equals(p1, p2));//Equals表示比较数值。而p1、p2有相同的数值(1,2),所以输出结果为true。

//            // The line below displays true because p1 and p3 refer to one object.
//            Console.WriteLine(Object.ReferenceEquals(p1, p3));//p1、p3是相同的object,所以输出结果为true

//            // The line below displays: p1's value is: (1, 2)
//            Console.WriteLine("p1's value is: {0}", p1.ToString());


//            Colors color = Colors.green;
//            string str = color.ToString();
//            Console.WriteLine(str);
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region object类的应用举例2。
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Net.Sockets;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//namespace test
//{
//    struct A
//    {
//        public int count;
//    }
//    class B
//    {
//        public int number;
//    }

//    class C
//    {
//        public int integer = 0;
//        public override bool Equals(object obj)
//        {
//            C c = obj as C;//往往采用这种格式将object类型转化你想要的类型。我的Socket学习博客,也采用到这种格式转换。
//            //String  str = obj as String;
//            //Socket socket = obj as Socket;
//            //Point point = obj as Point; //string、Socket、Point是系统自定的类

//            if (c != null)
//                return this.integer == c.integer;
//            else
//                return false;
//        }
//        public override int GetHashCode()
//        {
//            return 2 ^ integer;
//        }
//    }

//    class Program
//    {

//        static void Main(string[] args)
//        {
//            A a1, a2;
//            a1.count = 10;
//            a2 = a1;

//            //Console.Write(a1==a2);没有定义“==”操作符
//            Console.Write(a1.Equals(a2));//True
//            Console.WriteLine(object.ReferenceEquals(a1, a2));//False

//            B b1 = new B();
//            B b2 = new B();

//            b1.number = 10;
//            b2.number = 10;
//            Console.Write(b1 == b2);//False
//            Console.Write(b1.Equals(b2));//False
//            Console.WriteLine(object.ReferenceEquals(b1, b2));//False

//            b2 = b1;
//            Console.Write(b1 == b2);//True
//            Console.Write(b1.Equals(b2));//True
//            Console.WriteLine(object.ReferenceEquals(b1, b2));//True

//            C c1 = new C();
//            C c2 = new C();

//            c1.integer = 10;
//            c2.integer = 10;
//            Console.Write(c1 == c2);//False
//            Console.Write(c1.Equals(c2));//True
//            Console.WriteLine(object.ReferenceEquals(c1, c2));//False

//            c2 = c1;
//            Console.Write(c1 == c2);//True
//            Console.Write(c1.Equals(c2));//True
//            Console.WriteLine(object.ReferenceEquals(c1, c2));//True

//        }
//    }
//}
#endregion

#region 接口。
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Net.Sockets;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//namespace test
//{
//    struct A
//    {
//        public int count;
//    }
//    class B
//    {
//        public int number;
//    }

//    class C
//    {
//        public int integer = 0;
//        public override bool Equals(object obj)
//        {
//            C c = obj as C;//往往采用这种格式将object类型转化你想要的类型。我的Socket学习博客,也采用到这种格式转换。
//            //String  str = obj as String;
//            //Socket socket = obj as Socket;
//            //Point point = obj as Point; //string、Socket、Point是系统自定的类

//            if (c != null)
//                return this.integer == c.integer;
//            else
//                return false;
//        }
//        public override int GetHashCode()
//        {
//            return 2 ^ integer;
//        }
//    }

//    class Program
//    {

//        static void Main(string[] args)
//        {
//            A a1, a2;
//            a1.count = 10;
//            a2 = a1;

//            //Console.Write(a1==a2);没有定义“==”操作符
//            Console.Write(a1.Equals(a2));//True
//            Console.WriteLine(object.ReferenceEquals(a1, a2));//False

//            B b1 = new B();
//            B b2 = new B();

//            b1.number = 10;
//            b2.number = 10;
//            Console.Write(b1 == b2);//False
//            Console.Write(b1.Equals(b2));//False
//            Console.WriteLine(object.ReferenceEquals(b1, b2));//False

//            b2 = b1;
//            Console.Write(b1 == b2);//True
//            Console.Write(b1.Equals(b2));//True
//            Console.WriteLine(object.ReferenceEquals(b1, b2));//True

//            C c1 = new C();
//            C c2 = new C();

//            c1.integer = 10;
//            c2.integer = 10;
//            Console.Write(c1 == c2);//False
//            Console.Write(c1.Equals(c2));//True
//            Console.WriteLine(object.ReferenceEquals(c1, c2));//False

//            c2 = c1;
//            Console.Write(c1 == c2);//True
//            Console.Write(c1.Equals(c2));//True
//            Console.WriteLine(object.ReferenceEquals(c1, c2));//True

//        }
//    }
//}
#endregion

#region 集合;普通集合与类的集合
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Net.Sockets;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            #region 一、普通集合ArrayList与Add方法,引用了System.Collections命名空间
//            ArrayList myAL = new ArrayList();
//            myAL.Add("The");
//            myAL.Add("quick");
//            myAL.Add("brown");
//            myAL.Add("fox");
//            foreach (var list in myAL)
//            {             
//                Console.WriteLine(list.ToString());//输出集合的所有元素。
//            }
//            Console.WriteLine(myAL.IndexOf("brown"));//输出集合的指定元素的位置。
//            Console.WriteLine();
//            #endregion

//            #region 二、普通集合ArrayList与AddRange方法,引用了System.Collections命名空间
//            ArrayList myAL1 = new ArrayList();
//            myAL1.Add("The");
//            myAL1.Add("quick");
//            myAL1.Add("brown");
//            myAL1.Add("fox");
//            Queue myQueue = new Queue();
//            myQueue.Enqueue("jumped");
//            myQueue.Enqueue("over");
//            myQueue.Enqueue("the");
//            myQueue.Enqueue("lazy");
//            myQueue.Enqueue("dog");
//            myAL1.AddRange(myQueue);//将集合myQueue的所有元素添加到集合myAL1的末尾。
//            foreach (var list in myAL1)
//            {
//                Console.WriteLine(list.ToString());//输出集合的所有元素。
//            }
//            Console.WriteLine();
//            #endregion

//            #region 三、泛型集合List<T>与Add方法,引用了System.Collections.Generic命名空间
//            List<string> dinosaurs = new List<string>();
//            dinosaurs.Add("Tyrannosaurus");
//            dinosaurs.Add("Amargasaurus");
//            dinosaurs.Add("Mamenchisaurus");
//            dinosaurs.Add("Deinonychus");
//            dinosaurs.Add("Compsognathus");
//            foreach (var list in dinosaurs)
//            {
//                Console.WriteLine(list.ToString());//输出集合的所有元素。
//            }
//            Console.WriteLine();
//            #endregion

//            #region 四、泛型集合List<T>与AddRange方法,引用了System.Collections.Generic命名空间
//            string[] input = { "Brachiosaurus", "Amargasaurus", "Mamenchisaurus" };
//            List<string> dinosaurs2 = new List<string>();
//            dinosaurs2.AddRange(input);
//            foreach (var list in dinosaurs2)
//            {
//                Console.WriteLine(list.ToString());//输出集合的所有元素。
//            }
//            Console.WriteLine();
//            #endregion


//            #region 五、自定义泛型集合
//            List<Person> personList = new List<Person>()
//            {
//                 new Person(){ Name="a", Age=2 },
//                 new Person(){ Name="d", Age=9 },
//                 new Person(){ Name = null, Age=3 },//Name可以设置为空值
//                 new Person(){ Name="c", }          //Age默认值为0
//             };
//            foreach (var list in personList)
//            {
//                Console.WriteLine(list.Name + "-" + list.Age);
//            }

//            Console.WriteLine();
//            personList[0].Name = "aaaa";                            //更改集合的某条记录的某个属性值。
//            foreach (var list in personList)
//            {
//                Console.WriteLine(list.Name + "-" + list.Age);
//            }
//            Console.WriteLine();

//            //往集合中添加几条条记录
//            personList.Add(new Person() { Name = "dd", Age = 44 }); //Add方法:在末尾插入
//            personList.Add(new Person() { Name = "ee", Age = 55 });
//            personList.Add(new Person() { Name = "ee", Age = 55 });
//            personList.Add(new Person() { Name = "ff", Age = 55 });
//            personList.Insert(1,new Person() { Name = "two", Age = 222 }); //Insert方法:在指定位置插入
//            personList.AddRange(new List<Person>()                  //AddRange方法 
//            {
//                new Person(){ Name="HH", Age=66 },
//                new Person(){ Name="II", Age=77 },
//            });
//            foreach (var list in personList)
//            {
//                Console.WriteLine(list.Name + "-" + list.Age);      
//            }
//            Console.WriteLine();

//            //删除集中第一条记录
//            personList.RemoveRange(0,1);                            
//            foreach (var list in personList)
//            {
//                Console.WriteLine(list.Name + "-" + list.Age);       
//            }
//            Console.WriteLine();

//            //拷贝集合到
//            List<Person> personList2 = new List<Person>();
//            personList2 = personList;                               
//            foreach (var list in personList2)
//            {
//                Console.WriteLine(list.Name + "-" + list.Age);
//            }
//            Console.WriteLine();
//            //Array.ConstrainedCopy(personList, 0, personList2, 0, 2); //字节拷贝常用ConstrainedCopy这种方法       

//            //检索集合:根据某种条件检索。
//            List<Person> personList3 = personList2.FindAll(p => p.Age == 55);//FindAll方法。
//            foreach (var list in personList3)
//            {
//                Console.WriteLine(list.Name + "-" + list.Age);
//            }
//            Console.WriteLine();
//            #endregion

//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region 值类型和应用类型
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Net.Sockets;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//namespace test
//{

//    public class ClassValue
//    {
//        public int a;
//        public int b;
//        public string str1;
//        public string str2;
//    }
//    class Program
//    {
//        static void Main(string[] args)
//        {

//            #region 一、自定义泛型集合是属于引用类型
//            List<ClassValue> List1 = new List<ClassValue>();
//            List<ClassValue> List2 = new List<ClassValue>();

//            //分别赋值
//            List1.Add(new ClassValue { a = 100, b = 200, str1 = "aaaa", str2 = "bbbb" });
//            List2 = List1;
//            //List2 = new List<ClassValue>();
//            //List2.AddRange(List1);
//            //Array.Copy(List1.ToArray(), List2.ToArray(), 1);

//            //直接输出
//            Console.WriteLine("");
//            Console.WriteLine("");
//            Console.WriteLine("-------------------直接输出------------------");
//            Console.WriteLine("a = {0}, b = {1}, str1 = {2}, str2 = {3}", List1[0].a, List1[0].b, List1[0].str1, List1[0].str2);
//            Console.WriteLine("a = {0}, b = {1}, str1 = {2}, str2 = {3}", List2[0].a, List2[0].b, List2[0].str1, List2[0].str2);

//            //我们现在来改变List1,看看List2是否也跟着改变
//            List1[0].a = 111;
//            List1[0].str1 = "ljflaj";
//            Console.WriteLine("");
//            Console.WriteLine("");
//            Console.WriteLine("-------------------改变List1,List2也改变------------------");
//            Console.WriteLine("a = {0}, b = {1}, str1 = {2}, str2 = {3}", List1[0].a, List1[0].b, List1[0].str1, List1[0].str2);
//            Console.WriteLine("a = {0}, b = {1}, str1 = {2}, str2 = {3}", List2[0].a, List2[0].b, List2[0].str1, List2[0].str2);

//            //我们现在来改变List2,看看List1是否也跟着改变
//            List2[0].a = 12121212;
//            List2[0].str1 = "我我我";
//            Console.WriteLine("");
//            Console.WriteLine("");
//            Console.WriteLine("-------------------改变List2,List1也改变------------------");
//            Console.WriteLine("a = {0}, b = {1}, str1 = {2}, str2 = {3}", List1[0].a, List1[0].b, List1[0].str1, List1[0].str2);
//            Console.WriteLine("a = {0}, b = {1}, str1 = {2}, str2 = {3}", List2[0].a, List2[0].b, List2[0].str1, List2[0].str2);
//            #endregion

//            #region 二、字符串List集合是属于值类型
//            List<string> stringList1 = new List<string>();
//            List<string> stringList2 = new List<string>();
//            //赋值
//            stringList1.Add("AAA");
//            stringList1.Add("BBB");

//            stringList2.Add("AAA");
//            stringList2.Add("BBB");
//            //输出
//            Console.WriteLine("-------------------直接输出------------------");
//            Console.WriteLine("字符串1 = {0}, 字符串2 = {1}", stringList1[0], stringList1[1]);
//            Console.WriteLine("字符串1 = {0}, 字符串2 = {1}", stringList2[0], stringList2[1]);

//            //我们现在来改变stringList1,看看stringList2是否也跟着改变
//            stringList1[0] = "--***111";
//            Console.WriteLine("");
//            Console.WriteLine("-------------------改变stringList1,stringList2不会改变------------------");
//            Console.WriteLine("字符串1 = {0}, 字符串2 = {1}", stringList1[0], stringList1[1]);
//            Console.WriteLine("字符串1 = {0}, 字符串2 = {1}", stringList2[0], stringList2[1]);
//            #endregion

//            #region 三、字符串集合是属于值类型
//            string[] str1 = { "111", "222" };
//            string[] str2 = { "111", "222" };

//            //输出
//            Console.WriteLine();
//            Console.WriteLine("-------------------直接输出------------------");
//            Console.WriteLine("字符串1 = {0}, 字符串2 = {1}", str1[0], str1[1]);
//            Console.WriteLine("字符串1 = {0}, 字符串2 = {1}", str2[0], str2[1]);

//            //我们现在来改变str1,看看str2是否也跟着改变
//            str1[0] = "--***111";
//            Console.WriteLine("");
//            Console.WriteLine("-------------------改变str1,str2不会改变------------------");
//            Console.WriteLine("字符串1 = {0}, 字符串2 = {1}", str1[0], str1[1]);
//            Console.WriteLine("字符串1 = {0}, 字符串2 = {1}", str2[0], str2[1]);
//            #endregion

//            #region 四、int集合是属于值类型
//            int[] int1 = { 100, 200 };
//            int[] int2 = { 100, 200 };

//            //输出
//            Console.WriteLine();
//            Console.WriteLine("-------------------直接输出------------------");
//            Console.WriteLine("整数1 = {0}, 整数2 = {1}", int1[0], int1[1]);
//            Console.WriteLine("整数1 = {0}, 整数2 = {1}", int2[0], int2[1]);

//            //我们现在来改变int1,看看int2是否也跟着改变
//            int1[0] = 111;
//            Console.WriteLine("");
//            Console.WriteLine("-------------------改变int1,int2不会改变------------------");
//            Console.WriteLine("整数1 = {0}, 整数2 = {1}", int1[0], int1[1]);
//            Console.WriteLine("整数1 = {0}, 整数2 = {1}", int2[0], int2[1]);
//            #endregion

//            #region 五、new int[]集合是属于值类型
//            int[] int11 = new int[] { 100, 200 };
//            int[] int22 = new int[] { 100, 200 };

//            //输出
//            Console.WriteLine();
//            Console.WriteLine("-------------------直接输出------------------");
//            Console.WriteLine("整数1 = {0}, 整数2 = {1}", int11[0], int11[1]);
//            Console.WriteLine("整数1 = {0}, 整数2 = {1}", int22[0], int22[1]);

//            //我们现在来改变int1,看看int2是否也跟着改变
//            int11[0] = 111;
//            Console.WriteLine("");
//            Console.WriteLine("-------------------改变int11,int22不会改变------------------");
//            Console.WriteLine("整数1 = {0}, 整数2 = {1}", int11[0], int11[1]);
//            Console.WriteLine("整数1 = {0}, 整数2 = {1}", int22[0], int22[1]);
//            #endregion
//            Console.ReadLine();
//        }   
//    }
//}
#endregion


#region 将文件夹拷贝到另一个文件夹
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Net.Sockets;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//namespace test
//{
//    class Program
//    {

//        static void Main(string[] args)
//        {

//            string pLocalFilePath = @"C:\Users\lanmage2\Desktop\aaaa";//要复制的文件路径
//            string pSaveFilePath = @"C:\Users\lanmage2\Desktop\bbbb";//指定存储的路径
//            CopyDirectory(pLocalFilePath, pSaveFilePath);
//        }

//        /// <summary>
//        /// 复制文件夹中的所有内容
//        /// </summary>
//        /// <param name="sourceDirPath">源文件夹目录</param>
//        /// <param name="saveDirPath">指定文件夹目录</param>
//        public static void CopyDirectory(string sourceDirPath, string saveDirPath)
//        {
//            try
//            {
//                //如果指定的存储路径不存在,则创建该存储路径
//                if (!Directory.Exists(saveDirPath))
//                {
//                    //创建
//                    Directory.CreateDirectory(saveDirPath);
//                }

//                //获取源路径文件的名称
//                string[] files = Directory.GetFiles(sourceDirPath);

//                //遍历子文件夹的所有文件。
//                foreach (string file in files)
//                {
//                    string pFilePath = saveDirPath + "\\" + Path.GetFileName(file);
//                    if (File.Exists(pFilePath))
//                        continue;
//                    File.Copy(file, pFilePath, true);
//                }

//                string[] dirs = Directory.GetDirectories(sourceDirPath);

//                //递归,遍历文件夹
//                foreach (string dir in dirs)
//                {
//                    CopyDirectory(dir, saveDirPath + "\\" + Path.GetFileName(dir));
//                }
//            }
//            catch (Exception ex)
//            {

//            }
//        }  

//    }
//}
#endregion

#region 日期格式
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Net.Sockets;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            DateTime dt = DateTime.Now;

//            Console.WriteLine(dt);
//            Console.WriteLine(dt.ToShortTimeString().ToString());
//            Console.WriteLine(dt.ToLongTimeString().ToString());
//            Console.WriteLine(dt.ToShortDateString().ToString());
//            DateTime dt2=  Convert.ToDateTime(dt.ToShortDateString().ToString());
//            Console.WriteLine(dt.ToLongDateString().ToString());
//            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
//            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd"));
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region using释放内存

//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Net.Sockets;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            string s = null;
//            using (StreamReader sr = new StreamReader(@"C:\Users\lanmage2\Desktop\1212.jpg"))
//            {
//                s = sr.ReadToEnd();
//                Console.WriteLine(s.Count());
//            }
//            Console.WriteLine(s.Count());
//            Console.WriteLine(s.Length);
//            //Console.WriteLine(sr.ReadToEnd().Length);//sr已经被释放,所以这行代码无效。
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region 三角函数和反三角函数
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Messaging;
//using System.Net.Sockets;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//namespace test
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            #region 正弦、反正弦
//            //正弦
//            double sinAngleValue1 = 150;//角度值:30度。
//            double sinRadianValue1 = Math.PI * sinAngleValue1 / 180;//求弧度值
//            double sinValue1 = Math.Sin(sinRadianValue1);//求sin30度,其实sin30度 = sin(PI/6),但是,数学上或代码上,常常用弧度PI/6,来计算sin(PI/6),其他函数同理。
//            Console.WriteLine(sinValue1);
//            //反正弦
//            double sinValue2 = 0.5;//正弦值 = 0.5。
//            double sinRadianValue2 = Math.Asin(sinValue2);//求弧度值
//            double sinAngleValue2 = sinRadianValue2 / Math.PI * 180;//根据弧度值,来求角度值。
//            Console.WriteLine(sinAngleValue2);
//            Console.WriteLine();
//            #endregion

//            #region 正切、正切
//            Console.WriteLine();
//            Console.WriteLine();
//            //正切
//            double tanAngleValue1 = 15;//角度值
//            double tanRadianValue1 = Math.PI * tanAngleValue1 / 180;//求弧度值
//            double tanValue1 = Math.Tan(tanRadianValue1);//tan值
//            Console.WriteLine("tan" + "(" + tanAngleValue1 + ")" + "=" + tanValue1);//tan值
//            Console.WriteLine((1.36 - 0.878) / tanValue1);//tan值

//            //double tanValue2 = 1;
//            //double tanRadianValue2 = Math.Atan(tanValue2);//求弧度值
//            //double tanAngleValue2 = tanRadianValue2 / Math.PI * 180;//求角度
//            //Console.WriteLine(tanAngleValue2);//角度值
//            #endregion
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region List<byte> 列表 队列
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace QueueSample
//{
//    class Program
//    {
//        static List<byte> VideoList = new List<byte>();      
//        const int IMAGE_LENGHT = 3;
//        byte[] btBitmapImage = new byte[IMAGE_LENGHT];
//        static void Main(string[] args)
//        {
//            byte[] byteC = new byte[3] { 3, 3,3};
//            VideoQuene(byteC);
//        }

//        private static byte[] VideoQuene(byte[] btVedioRecByte)
//        {
//            byte[] byteD = new byte[4] { 4, 4, 4, 4 };
//            byte[] byteB = new byte[2] { 2, 2 };

//            //插入:一个一个字节插入
//            VideoList.Add(2);
//            VideoList.Add(3);
//            VideoList.Add(10);
//            VideoList.Add(32);
//            VideoList.Add(12);

//            //插入:将字节数组插入到末尾
//            VideoList.AddRange(byteD);
//            VideoList.AddRange(btVedioRecByte);

//            //拷贝
//            byte[] btBitmapImage = new byte[IMAGE_LENGHT];
//            Array.Copy(VideoList.ToArray(), btBitmapImage, IMAGE_LENGHT); //将List<byte>的内容拷贝到byte[]:VideoList.ToArray()

//            //删除
//            VideoList.RemoveRange(0, IMAGE_LENGHT);
//            return btBitmapImage;
//        }
//    }
//}
#endregion

#region  
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace QueueSample
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            string str = "你aabbbfjalj444我";
//            List<char> StringList = new List<char>();
//            StringList = str.ToList();
//            Console.WriteLine(str);
//            Console.WriteLine(StringList[0].ToString());
//            Console.WriteLine(StringList[0]);

//            int a = StringList.Find(xxx => xxx.Equals( '我'));
//            int b = StringList.FindIndex(xxx => xxx.Equals('我'));
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region 字节与图片的互转
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace QueueSample
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {

//            string path = @"C:\Users\lanmage2\Desktop\aaa4.Gif";
//            ImageConvertToByte(path);
//            ImageConvertToByte(ImageConvertToByte(path));
//            Console.ReadLine();
//        }
//        /// <summary>
//        /// 图片转字节
//        /// </summary>
//        /// <param name="Path"></param>
//        /// <returns></returns>
//        static byte[] ImageConvertToByte(string Path)
//        {
//            FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read);
//            Byte[] btye2 = new byte[fs.Length];
//            fs.Read(btye2, 0, Convert.ToInt32(fs.Length));
//            fs.Close();
//            return btye2;
//        }

//        /// <summary>
//        /// 字节转图片
//        /// </summary>
//        /// <param name="ImageByte"></param>
//        /// <returns></returns>
//        static Image ImageConvertToByte(byte[] ImageByte)
//        {
//            System.IO.MemoryStream ms = new System.IO.MemoryStream(ImageByte);
//            Image img = Image.FromStream(ms);
//            img.Save(@"C:\Users\lanmage2\Desktop\aaa4.Gif", System.Drawing.Imaging.ImageFormat.Gif);
//            return img;
//        }
//    }
//}
//#endregion

//#region 字节与图片的互转
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace QueueSample
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {

//            byte[] bytSendFlagVar = new byte[4];
//            bytSendFlagVar = BitConverter.GetBytes(8);

//            string str = "1234";
//            byte[] bytContentLongVar = new byte[4];
//            bytContentLongVar = BitConverter.GetBytes(str.Length);
//            Console.ReadLine();
//        }

//    }
//}
#endregion

#region 委托\回调
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//using test;

//namespace QueueSample
//{
//    class Program
//    {
//        public delegate int MethodDelegate(int x, int y);
//        public delegate int MyDel(int name);
//        private static MethodDelegate method;

//        public delegate void MethodDelegateA(int x, int y);
//        private static MethodDelegateA methodA;
//        static void Main(string[] args)
//        {
//            /*一、委托只调用一个静态方法*/
//            Console.WriteLine("一、委托只调用一个静态方法");
//            method = new MethodDelegate(DelegateMethon.Add);
//            int aa = method(10, 20);
//            Console.WriteLine(method(10, 20));
//            methodA = new MethodDelegateA(DelegateMethon.Add3);
//            methodA(11, 99);

//            /*二、委托同时调用两个静态方法*/
//            Console.WriteLine("二、委托同时调用两个静态方法");
//            var add = new MyDel(DelegateMethon.Add1);
//            add += new MyDel(DelegateMethon.Add2);//多播委托:委托重载Add2方法。相当于一个委托可以加载多个方法。
//            add(10);


//            /*三、回调函数1:*/
//            Console.WriteLine("三、回调函数1:");
//            CallBackClasss c = new CallBackClasss();
//            c.TestCallBack(PublicFunc.CallBack);
//            Console.ReadLine();
//        }    
//    }
//}
#endregion

#region 读Josn数据
//using System;
//using System.Collections.Generic;
//using System.ComponentModel;
//using System.Data;
//using System.Drawing;
//using System.Linq;
//using System.Text;
//using System.Windows.Forms;

//using Newtonsoft.Json;

//namespace QueueSample
//{
//    class Program
//    {

//        public class Info1
//        {
//            public string phantom { get; set; }
//            public string id { get; set; }
//            public data1 data { get; set; }
//        }

//        public class data1
//        {
//            public int MID { get; set; }
//            public string Name { get; set; }
//            public string Des { get; set; }
//            public string Disable { get; set; }
//            public string Remark { get; set; }
//        }

//        public class Info2
//        {
//            public int Age { get; set; }
//            public int ID { get; set; }
//            public string Name { get; set; }
//            public int Score { get; set; }
//        }

//        #region info3
//        public class Info3
//        {
//            public string imagePath { get; set; }
//            public Data3 data { get; set; }
//            public string status_code { get; set; }
//        }

//        public class Data3
//        {
//            public bool is_normal { get; set; }
//            public bool is_negative { get; set; }
//            public List<string> disease_list { get; set; }
//            public List<DetectList> Detect_list { get; set; }
//        }

//        public class DetectList
//        {
//            public float prob;//必须加public
//            public int x1;
//            public int y1;
//            public int x2;
//            public int y2;
//            public int width;
//            public int height;
//            public string disease;
//        }

//        #endregion


//        /*C# 读取Json数据,有效的方法两种 */
//        static void Main(string[] args)
//        {
//            /* 没病的数据:错误的写法 */
//            string data1= @"[{'imagePath': 'e:\\bin\\DiCom\\z.dcm', 'data': {'is_negative': false, 'is_normal': true, 'disease_list': [], 'detect_list': []}, 'status_code': 1000}]";
//            string data11 = @"[{'imagePath': 'e:\\bin\\DiCom\\z.dcm','status_code': 1000}]";
//            /* 有病的数据:错误的写法 */
//            //string data2={"imagePath": "e:\\bin\\DiCom\\z.dcm", "data": {"is_negative": false, "is_normal": false, "disease_list": ["Infiltration", "Mass", "Nodule", "Pneumothorax", "Consolidation", "Emphysema", "Fibrosis", "Pleural_Thickening", "abnormal"], "detect_list": [{"prob": 1.0, "x1": 2138, "y1": 1236, "x2": 2193, "y2": 1297, "width": 55, "height": 61, "disease": "Nodule"}, {"prob": 0.99, "x1": 1016, "y1": 1333, "x2": 1096, "y2": 1451, "width": 80, "height": 118, "disease": "Nodule"}, {"prob": 0.99, "x1": 777, "y1": 747, "x2": 843, "y2": 824, "width": 66, "height": 77, "disease": "Nodule"}, {"prob": 0.98, "x1": 857, "y1": 1066, "x2": 943, "y2": 1150, "width": 86, "height": 84, "disease": "Nodule"}, {"prob": 0.96, "x1": 1803, "y1": 634, "x2": 2306, "y2": 1029, "width": 503, "height": 395, "disease": "Pneumonia"}, {"prob": 0.95, "x1": 1162, "y1": 1837, "x2": 1305, "y2": 1941, "width": 143, "height": 104, "disease": "Mass"}]}, "status_code": 1000};

//            //单引号:正确的写法,可以解析成结构体,可以通过Json格式在线解析
//            string json1 = @"[{'phantom':true,'id':'20130717001','data':{'MID':1019,'Name':'aaccccc','Des':'cc','Disable':'启用','Remark':'cccc'}}]";
//            //单引号:正确的写法,可以解析成结构体,可以通过Json格式在线解析
//            string json2 = @"{'phantom':true,'id':'20130717001','data':{'MID':1019,'Name':'aaccccc','Des':'cc','Disable':'启用','Remark':'cccc'}}";

//            //双引号:正确的写法,必须加[]才能被解析
//            string json3= "[{\"phantom\":true,\"id\":20130717001,\"data\":{\"MID\":1019,\"Name\":aaccccc,\"Des\":cc,\"Disable\":启用,\"Remark\":cccc}}]";

//            ///双引号:正确的的写法,可以通过Json格式在线解析,不可以被C#解析,必须加[]才能被解析。
//            string json5 = "{\"Name\" : \"战神\",\"ByName\" : [\"男\",\"女\",\"人妖\"],\"Education\":{\"GradeSchool\" : \"第一小学\",\"MiddleSchool\" : [\"第一初中\" , \"第一高中\"], \"University\" :{ \"Name\" : \"清华\", \"Grand\" : [\"一年级\",\"二年级\"]}}}";
//            ///双引号:正确的的写法,可以通过Json格式在线解析,不可以被C#解析,必须加[]才能被解析。
//            string json6 = "{\"Age\":25,\"ID\":3,\"Name\":\"王二麻子\",\"Score\":59}";
//            //双引号:正确的的写法,可以通过Json格式在线解析,可以被C#解析
//            string json7  = "[{\"Age\":25,\"ID\":3,\"Name\":\"王二麻子\",\"Score\":59}]";
//            //string json71 = "{ "Age":25,"ID":3,"Name":"王二麻子","Score":59}";

//            /*json8源数据*/
//            //string json8 = "[{\"imagePath\": \"e:\\bin\\DiCom\\z.dcm\", \"data\": {\"is_negative\": false, \"is_normal\": true, \"disease_list\": [\"男\",\"女\",\"人妖\"], \"detect_list\": [{\"prob\": 0.99, \"x1\": 1016, \"y1\": 1333, \"x2\": 1096,  \"y2 \": 1451,  \"width \": 80,  \"height \": 118,  \"disease \":  \"Nodule \"}]}, \"status_code\": 1000}]";
//            string json81 = "[{\"imagePath\": \"e:\\bin\\DiCom\\z.dcm\", \"data\": {\"is_negative\": false, \"is_normal\": true, \"disease_list\": [\"男\",\"女\",\"人妖\"], \"detect_list\": []}, \"status_code\": 1000}]";
//            //去掉
//            string json82 = "[{\"imagePath\":\"e:\\bin\\\\DiCom\\\\z.dcm\",\"data\":{\"is_negative\": false, \"is_normal\": true, \"disease_list\": [\"男\",\"女\",\"人妖\"], \"detect_list\": []},\"status_code\":1000}]";
//            string json83 = "[{\"imagePath\":\"e:\\bin\\DiCom\\\\z.dcm\",\"data\":{\"is_negative\": false, \"is_normal\": true, \"disease_list\": [\"Infiltration\", \"Mass\", \"Nodule\", \"Pneumothorax\", \"Consolidation\", \"Emphysema\", \"Fibrosis\", \"Pleural_Thickening\", \"abnormal\"], \"detect_list\": [{\"prob\": 1.0, \"x1\": 2138, \"y1\": 1236, \"x2\": 2193, \"y2\": 1297, \"width\": 55, \"height\": 61, \"disease\": \"Nodule\"}, {\"prob\": 0.99, \"x1\": 1016, \"y1\": 1333, \"x2\": 1096, \"y2\": 1451, \"width\": 80, \"height\": 118, \"disease\": \"Nodule\"}, {\"prob\": 0.99, \"x1\": 777, \"y1\": 747, \"x2\": 843, \"y2\": 824, \"width\": 66, \"height\": 77, \"disease\": \"Nodule\"}, {\"prob\": 0.98, \"x1\": 857, \"y1\": 1066, \"x2\": 943, \"y2\": 1150, \"width\": 86, \"height\": 84, \"disease\": \"Nodule\"}, {\"prob\": 0.96, \"x1\": 1803, \"y1\": 634, \"x2\": 2306, \"y2\": 1029, \"width\": 503, \"height\": 395, \"disease\": \"Pneumonia\"}, {\"prob\": 0.95, \"x1\": 1162, \"y1\": 1837, \"x2\": 1305, \"y2\": 1941, \"width\": 143, \"height\": 104, \"disease\": \"Mass\"}]},\"status_code\":1000}]";
//            string json84 = "[{\"imagePath\":\"D:\\\\StudyImage\\\\1.2.276.0.7230010.3.1.2.156673709.1904.1552620956.965\\\\DRImage\\\\1.2.276.0.7230010.3.1.3.156673709.1904.1552620985.966\\\\1.2.276.0.7230010.3.1.3.156673709.1904.1552620985.966_1_DR_1.dcm\",\"data\":{\"is_negative\": false, \"is_normal\": true, \"disease_list\": [\"Infiltration\", \"Mass\", \"Nodule\", \"Pneumothorax\", \"Consolidation\", \"Emphysema\", \"Fibrosis\", \"Pleural_Thickening\", \"abnormal\"], \"detect_list\": [{\"prob\": 1.0, \"x1\": 2138, \"y1\": 1236, \"x2\": 2193, \"y2\": 1297, \"width\": 55, \"height\": 61, \"disease\": \"Nodule\"}, {\"prob\": 0.99, \"x1\": 1016, \"y1\": 1333, \"x2\": 1096, \"y2\": 1451, \"width\": 80, \"height\": 118, \"disease\": \"Nodule\"}, {\"prob\": 0.99, \"x1\": 777, \"y1\": 747, \"x2\": 843, \"y2\": 824, \"width\": 66, \"height\": 77, \"disease\": \"Nodule\"}, {\"prob\": 0.98, \"x1\": 857, \"y1\": 1066, \"x2\": 943, \"y2\": 1150, \"width\": 86, \"height\": 84, \"disease\": \"Nodule\"}, {\"prob\": 0.96, \"x1\": 1803, \"y1\": 634, \"x2\": 2306, \"y2\": 1029, \"width\": 503, \"height\": 395, \"disease\": \"Pneumonia\"}, {\"prob\": 0.95, \"x1\": 1162, \"y1\": 1837, \"x2\": 1305, \"y2\": 1941, \"width\": 143, \"height\": 104, \"disease\": \"Mass\"}]},\"status_code\":1000}]";


//            Console.WriteLine();
//            Console.WriteLine("json1被解析后:");
//            List<Info1> list1 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Info1>>(json1);
//            foreach (Info1 jobInfo1 in list1)
//            {
//                Console.WriteLine("ID:" + jobInfo1.id);
//                Console.WriteLine("data.MID:" + jobInfo1.data.MID);
//            }

//            Console.WriteLine();
//            Console.WriteLine("json7被解析后:");
//            List<Info2> list2 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Info2>>(json7);
//            foreach (Info2 jobInfo2 in list2)
//            {
//                Console.WriteLine("Age:" + jobInfo2.Age);
//                Console.WriteLine("ID:" + jobInfo2.ID);
//                Console.WriteLine("UserName:" + jobInfo2.Name);
//                Console.WriteLine("Scorce:" + jobInfo2.Score);
//            }

//            Console.WriteLine();
//            Console.WriteLine("json82被解析后:");
//            List<Info3> list3 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Info3>>(json84);
//            foreach (Info3 jobInfo3 in list3)
//            {
//                Console.WriteLine("imagePath:" + jobInfo3.imagePath);
//                //Console.WriteLine("data:" + jobInfo.data);
//                Console.WriteLine("status_code:" + jobInfo3.status_code);
//            }

//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region Array.ConstrainedCopy字节拷贝,末尾自动补零
//using System;
//using System.Collections.Generic;
//using System.ComponentModel;
//using System.Data;
//using System.Drawing;
//using System.Linq;
//using System.Text;
//using System.Windows.Forms;

//using Newtonsoft.Json;

//namespace QueueSample
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {


//            byte[] bytTemp = new byte[3] { 66,33,11};
//            byte[] bytPackage = new byte[2048];//一个包的大小。   
//            Array.ConstrainedCopy(bytTemp, 0, bytPackage, 0, 3);
//            List<byte> bytPictureContentList = new List<byte>() { };//将图片内容放到队列中。
//            bytPictureContentList.AddRange(bytTemp);
//            Array.ConstrainedCopy(bytPictureContentList.ToArray(), 0, bytPackage, 3, 3);

//            byte[] bytPackageHeadVar = new byte[4] { 0, 0, 0, 0 };
//            const int PACKAGE_CONTENT_SIZE = 258;
//            bytPackageHeadVar = BitConverter.GetBytes(PACKAGE_CONTENT_SIZE);//将int32转换为字节数组
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region 字节与图片的互转
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace QueueSample
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {

//            string path = @"C:\Users\lanmage2\Desktop\aaa4.Gif";
//            ImageConvertToByte(path);
//            ImageConvertToByte(ImageConvertToByte(path));
//            Console.ReadLine();
//        }
//        /// <summary>
//        /// 图片转字节
//        /// </summary>
//        /// <param name="Path"></param>
//        /// <returns></returns>
//        static byte[] ImageConvertToByte(string Path)
//        {
//            FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read);
//            Byte[] btye2 = new byte[fs.Length];
//            fs.Read(btye2, 0, Convert.ToInt32(fs.Length));
//            fs.Close();
//            return btye2;
//        }

//        /// <summary>
//        /// 字节转图片
//        /// </summary>
//        /// <param name="ImageByte"></param>
//        /// <returns></returns>
//        static Image ImageConvertToByte(byte[] ImageByte)
//        {
//            System.IO.MemoryStream ms = new System.IO.MemoryStream(ImageByte);
//            Image img = Image.FromStream(ms);
//            img.Save(@"C:\Users\lanmage2\Desktop\aaa4.Gif", System.Drawing.Imaging.ImageFormat.Gif);
//            return img;
//        }
//    }
//}
#endregion

#region 字节与图片的互转
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace QueueSample
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {

//            byte[] bytSendFlagVar = new byte[4];
//            bytSendFlagVar = BitConverter.GetBytes(8);

//            string str = "1234";
//            byte[] bytContentLongVar = new byte[4];
//            bytContentLongVar = BitConverter.GetBytes(str.Length);
//            Console.ReadLine();
//        }

//    }
//}
#endregion

#region .dcm与字节的互转
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;

//namespace QueueSample
//{
//    class Program
//    {

//        static void Main(string[] args)
//        {

//            string path = @"C:\Users\lanmage2\Desktop\22.dcm";
//            ByteConvertToImage(ImageConvertToByte(path));
//            Console.ReadLine();
//        }
//        /// <summary>
//        /// 图片转字节
//        /// </summary>
//        /// <param name="Path"></param>
//        /// <returns></returns>
//        static byte[] ImageConvertToByte(string Path)
//        {
//            FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read);
//            Byte[] btye2 = new byte[fs.Length];
//            fs.Read(btye2, 0, Convert.ToInt32(fs.Length));
//            fs.Close();
//            return btye2;
//        }

//        /// <summary>
//        /// 字节转图片
//        /// </summary>
//        /// <param name="ImageByte"></param>
//        /// <returns></returns>
//        static void ByteConvertToImage(byte[] bytContent)
//        {
//            System.Windows.Forms.SaveFileDialog save = new System.Windows.Forms.SaveFileDialog();//核心1
//            save.Filter = "dcm文件|*.dcm";//筛选
//            save.FileName = @"C:\Users\lanmage2\Desktop\2-2.dcm";//保存文件的名字
//            //App.Current.Dispatcher.Invoke((Action)delegate ()//STA问题自己百度解决吧。
//            //{
//                //if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK)//打开对话框
//                //{


//                    System.IO.File.WriteAllBytes(save.FileName, bytContent);//核心2
//                //}
//            //});
//        }
//    }
//}
#endregion

#region 事件(一个事件发布者,多个订阅者)
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;

//namespace QueueSample
//{
//    /***********发布器类***********/
//    public class EventTest
//    {
//        private int value;

//        public delegate void NumManipulationHandler();
//        public event NumManipulationHandler ChangeNum;
//        protected virtual void OnNumChanged()
//        {
//            if (ChangeNum != null)
//            {
//                ChangeNum(); /* 事件被触发 */
//            }
//            else
//            {
//                Console.WriteLine("event not fire");
//            }
//        }


//        public EventTest()
//        {
//            string str= null;
//            SetValue(str);
//        }


//        public void SetValue(string str)
//        {
//            if (str != null && str == "触发所有事件")
//            {
//               OnNumChanged();
//            }
//        }
//    }

//    /***********订阅器类***********/
//    public class subscribEvent1
//    {
//        public void printf1()
//        {
//            Console.WriteLine("event fire111111");
//            //Console.ReadKey(); /* 回车继续 */
//        }
//    }
//    public class subscribEvent2
//    {
//        public void printf2()
//        {
//            Console.WriteLine("event fire2222222");
//            //Console.ReadKey(); /* 回车继续 */
//        }
//    }

//    public class subscribEvent3
//    {
//        public void printf3()
//        {
//            Console.WriteLine("event fire3333333");
//            //Console.ReadKey(); /* 回车继续 */
//        }
//    }



//    /***********触发***********/
//    class Program
//    {

//        static void Main(string[] args)
//        {
//            EventTest e = new EventTest(); //实例化事件发布者
//            subscribEvent1 v1 = new subscribEvent1(); //实例化事件订阅者1
//            subscribEvent2 v2 = new subscribEvent2(); //实例化事件订阅者2
//            subscribEvent3 v3 = new subscribEvent3(); //实例化事件订阅者3
//            e.ChangeNum += new EventTest.NumManipulationHandler(v1.printf1); //订阅事件或者说是注册事件
//            e.ChangeNum += new EventTest.NumManipulationHandler(v2.printf2); //订阅事件或者说是注册事件
//            e.ChangeNum += new EventTest.NumManipulationHandler(v3.printf3); //订阅事件或者说是注册事件
//            e.SetValue("触发所有事件");//引发事件或者说是触发事件
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region 写XML文件

//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;

//namespace QueueSample
//{
//    /***********触发***********/
//    class Program
//    {

//        static void Main(string[] args)
//        {
//            //记录该波特率值到配置文件中
//            string strCOMconfigFilePath = @"D:\keenray6.2\trunk\Bin\Config" + "\\SocketAndBullHeadConfig.xml";
//            XDocument document = XDocument.Load(strCOMconfigFilePath);
//            //获取到XML的根元素进行操作
//            XElement root = document.Root;//根节点
//            XElement BullHeadRoot = root.Element("BullHead");                     //第二级节点
//            //BullHeadRoot.SetAttributeValue("BaudRate", 9600);
//            XElement BullHeadBaudRate = BullHeadRoot.Element("BaudRate");       //波特率
//            //BullHeadBaudRate.SetElementValue("BaudRate",9600);//设置子元素的值
//            //BullHeadBaudRate.SetAttributeValue("AAAA", 121212);//设置元素属性的值
//            BullHeadBaudRate.SetValue(38400);
//            document.Save(strCOMconfigFilePath);
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region 删除指定文件夹下的所有文件

//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//using test;

//namespace QueueSample
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            string path = @"C:\Users\lanmage2\Desktop\Bin";
//            FileManagement fm = new FileManagement();
//            //fm.DeleteFolderFileFunc(path);
//            fm.DeleteFolderFunc(path);
//            Console.ReadLine();
//        }
//    }
//}
#endregion

#region 测试一个函数多个Return返回值

//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Xml.Linq;
//using test;

//namespace QueueSample
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            bool sta1 = false;
//            sta1 = func();
//            Console.ReadLine();
//        }

//        private static bool func()
//        {
//            bool statue = false;
//            List<int> list = new List<int>() { 1, 2, 33, 44 };
//            foreach (int i in list)
//            {
//                if (i == 33)
//                {
//                    statue = true;
//                    return statue;
//                }
//            }
//            int a = 100;
//            if (a == 100)
//            {
//                statue = false;
//                return statue;
//            }
//            return statue;
//        }
//    }
//}
#endregion

#region 二维数组
//https://www.cnblogs.com/zblc2016/p/5721725.html

using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using test;

namespace QueueSample
{
    class Program
    {
        static void Main(string[] args)
        {
            TwoDimensionalArray();
            Console.ReadLine();
        }

        private static void TwoDimensionalArray()
        {
            int[,] array1 = new int[4, 2] { {11,22}, { 33, 44 }, { 55, 66 }, { 77, 88 }};
            int[,] array2 = new int[2, 2] ;
            Console.WriteLine("数组中所有维度的元素总数 = " + array1.Length);
            Console.WriteLine("数组中第0维度的维度大小 = " + array1.GetLength(0));
            Console.WriteLine("数组中第1维度的维度大小 = " + array1.GetLength(1));
            Console.WriteLine("-------------------打印第一个数组--------------------");
            printArray(array1);
            Console.WriteLine("-------------------打印第二个数组--------------------");
            printArray(array2);
        }

        private static void printArray(int[,] array)
        {
            for (int i = 0; i < array.GetLength(0); i++)
            {
                //for (int j = 0; j < array.GetLength(1); j++)
                //{
                //    Console.WriteLine(array[i,j]);
                //}
                Console.WriteLine("坐标({0},{1})" ,array[i, 0], array[i, 1]);
            }
        }
    }
}
#endregion

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我爱AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值