using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
  
namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            Node treeRoot = CreateTree();
            scanTree(treeRoot);
        }
  
        private static void scanTree(Node treeRoot)
        {
            List<Node> list = new List<Node>();
            list.Add(treeRoot);
            Node point = treeRoot;
            Write(treeRoot);
            while (true)
            {
                if (!list.Contains(point))
                { //上一轮是移除的操作
                    if (treeRoot.leftSon == point)
                    {//移除的是左结点
                        if (treeRoot.rightSon != null)
                        {
                            treeRoot = treeRoot.rightSon;
                            list.Add(treeRoot);
                            Write(treeRoot);
                            point = treeRoot;
                            continue;
                        }
                        list.Remove(treeRoot);
                        if (list.Count == 0)
                        {
                            break;
                        }
                        point = treeRoot;
                        treeRoot = list[list.Count - 1];
                    }
                    else
                    {//移除的是右结点
                        list.Remove(treeRoot);
                        if (list.Count == 0)
                        {
                            break;
                        }
                        point = treeRoot;
                        treeRoot = list[list.Count - 1];
                    }
                    continue;
                }
  
                if (treeRoot.leftSon != null)
                {
                    treeRoot = treeRoot.leftSon;
                    Write(treeRoot);
                    list.Add(treeRoot);
                    point = treeRoot;
                    continue;
                }
                if (treeRoot.rightSon != null)
                {
                    treeRoot = treeRoot.rightSon;
                    Write(treeRoot);
                    point = treeRoot;
                    list.Add(treeRoot);
                    continue;
                }
                if (treeRoot.leftSon == null && treeRoot.rightSon == null)
                {
                    list.Remove(treeRoot);
                    if (list.Count == 0)
                    {
                        break;
                    }
                    point = treeRoot;
                    treeRoot = list[list.Count - 1];
                }
            }
  
        }
  
        public static void Write(Node node)
        {
            Console.WriteLine(node.Data);
        }
  
        private static Node CreateTree()
        {
            Node a = new Node("A");
           a.leftSon = new Node("B");
            a.rightSon = new Node("C");
            
           a.leftSon.leftSon = new Node("D");
           a.leftSon.rightSon = new Node("E");
            
           a.rightSon.leftSon = new Node("F");
           a.rightSon.rightSon = new Node("G");
  
           a.leftSon.leftSon.leftSon = new Node("H");
           a.leftSon.leftSon.rightSon = new Node("I");
            return a;
        }
    }
  
    class Node
    {
        public string Data { get; set; }
        public Node leftSon { get; set; }
        public Node rightSon { get; set; }
  
        public Node(string data)
        {
            Data = data;
        }
    }
}

C#先序遍历二叉树(非递归)

using System;
using System.Text;
using System.IO;
using System.Security.Cryptography;
  
namespace CI
{
    class CI_Encrypt
    {
        private string key;
        private string hash_type = "sha1";
  
        public CI_Encrypt(string key = "")
        {
            if(key.Length > 0)
            {
                this.key = key;
            }
        }
        public string encode(string data)
        {
            RijndaelManaged aes = new RijndaelManaged();
            aes.KeySize = 256;
            aes.BlockSize = 256;
            aes.Padding = PaddingMode.Zeros;
            aes.Mode = CipherMode.CBC;
  
            aes.Key = this.get_key(key);
            aes.GenerateIV();
            var _IV = aes.IV;
  
            byte[] buffer;
              
            ICryptoTransform AESEncrypt = aes.CreateEncryptor(aes.Key, aes.IV);
            using (MemoryStream msEncrypt = new MemoryStream())
            {
                using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, AESEncrypt, CryptoStreamMode.Write))
                {
                    using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                    {
  
                        //Write all data to the stream.
                        swEncrypt.Write(data);
                    }
                    buffer = msEncrypt.ToArray();
                }
            }
  
            var enc = new byte [ _IV.Length + buffer.Length ];
  
            Array.Copy(_IV,enc ,_IV.Length);
            Array.Copy(buffer,0,enc,_IV.Length,buffer.Length);
  
            return this.add_cipher_noise(enc);
        }
  
        public string decode(string data)
        {
            string plainText;
            byte[] _enc_data = this.remove_cipher_noise(Convert.FromBase64String(data));
            using (RijndaelManaged aes = new RijndaelManaged())
            {
                aes.KeySize = 256;
                aes.BlockSize = 256;
                aes.Padding = PaddingMode.Zeros;
                aes.Mode = CipherMode.CBC;
                aes.Key = this.get_key(key);
                var _IV = new byte[aes.IV.Length];
                Array.Copy(_enc_data, _IV, _IV.Length);
                aes.IV = _IV;
                var endata = new byte[_enc_data.Length - aes.IV.Length];
                Array.Copy(_enc_data, aes.IV.Length, endata, 0, endata.Length);
  
                // Create a decrytor to perform the stream transform.
                ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
  
                // Create the streams used for decryption. 
                using (MemoryStream msDecrypt = new MemoryStream(endata))
                {
                    using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                    {
                        using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                        {
  
                            // Read the decrypted bytes from the decrypting stream 
                            // and place them in a string.
                            plainText = srDecrypt.ReadToEnd();
                        }
                    }
                }
  
            }
            return plainText;
        }
  
        public string add_cipher_noise(byte[] data)
        {
            string hashkey = this.hash(System.Text.Encoding.Default.GetString(this.get_key(this.key)));
            char[] keyChar = hashkey.ToCharArray();
            byte[] encrpytData = new byte[data.Length];
            for (int i = 0, j = 0; i < data.Length; i++, j++)
            {
                if (j >= hashkey.Length)
                {
                    j = 0;
                }
                var temp = (((int)data[i] + (int)keyChar[j]) % 256);
                encrpytData[i] = (byte)temp;
            }
            return System.Convert.ToBase64String(encrpytData);
        }
  
        public byte[] remove_cipher_noise(byte[] data)
        {
            string hashkey = this.hash(System.Text.Encoding.Default.GetString(this.get_key(this.key)));
            char[] keyChar = hashkey.ToCharArray();
            byte[] encrpytData = new byte[data.Length];
            int temp;
  
            for (int i = 0, j = 0; i < data.Length; i++, j++)
            {
                if (j >= hashkey.Length)
                {
                    j = 0;
                }
                temp = (int)data[i] - (int)keyChar[j];
                if(temp < 0)
                {
                    temp += 256;
                }
                encrpytData[i] = (byte)temp;
            }
            return encrpytData;
        }
  
        private string hash(string key)
        {
            byte[] hashBytes;
            if (this.hash_type == "sha1")
            {
                SHA1 sha = new SHA1CryptoServiceProvider();
                hashBytes = (sha.ComputeHash(System.Text.Encoding.Default.GetBytes(key)));
            }
            else
            {
                MD5 md5 = new MD5CryptoServiceProvider();
                hashBytes = (md5.ComputeHash(System.Text.Encoding.Default.GetBytes(key)));
            }
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                sb.Append(hashBytes[i].ToString("X2"));
            }
            return sb.ToString().ToLower();
        }
  
        private byte[] get_key(string key)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] hashBytes = (md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(key)));
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                sb.Append(hashBytes[i].ToString("X2"));
            }
            return System.Text.Encoding.Default.GetBytes(sb.ToString().ToLower());
        }
    }
}

用C#实现跟CI里面的加密解密

private void GetFrames(string pPath,  string pSavedPath)
{
    DrawImage.Image gif = DrawImage.Image.FromFile(pPath);
    Imaging.FrameDimension fd = new Imaging.FrameDimension(gif.FrameDimensionsList[0]);
    int count = gif.GetFrameCount(fd);
    for (int i = 0; i < count; i++)
    {
        gif.SelectActiveFrame(fd, i);
        gif.Save(pSavedPath + "\\\\frame_" + i + ".jpg", ImageFormat.Jpeg);
    }
}

GIF抽帧

// 倒置字符串 修改版,再次修改版
static public string Reverse( string s )
{
    char[] charArray = s.ToCharArray();
    Array.Reverse( charArray );
    return new string( charArray );
}

C#倒置字符串方法

using System;
using System.Collections;
using System.Runtime.Remoting;

namespace Utilities
{
    /// <summary>
    /// This class is used to obtain a Remoting object from a registered list of well known client
    /// types. Use this class instead of manually calling Activator.GetObject.
    /// </summary>
    /// <remarks>This class was taken from the book "Advanced .NET Remoting" by Ingo Rammer (pg. 185-186).</remarks>
    public class RemotingHelper
    {
        private static bool m_isInit;
        private static IDictionary m_wellKnownTypes;

        // Constructor made private to prevent unwanted instantiation
        private RemotingHelper() { }

        /// <summary>
        /// Used to get the Remoting object.
        /// </summary>
        /// <param name="type">The type of object to get.</param>
        /// <returns>An Object representing the well known type.</returns>
        /// <exception cref="System.Runtime.Remoting.RemotingException">Thrown when the type is not found.</exception>
        /// <example>
        /// <code>
        ///     ICustomType obj = (ICustomType)RemotingHelper.GetObject(typeof(ICustomType));
        /// </code>
        /// </example>
        public static Object GetObject(Type type)
        {
            if (!m_isInit)
            {
                InitTypeCache();
            }

            WellKnownClientTypeEntry entr = (WellKnownClientTypeEntry) m_wellKnownTypes[type];
            if (entr == null)
            {
                string asmName = type.Assembly.GetName().Name;
                string typeName = type.ToString();
                string msg = string.Format("Type '{0}' not found in assembly '{1}'", typeName, asmName);
                throw new RemotingException(msg);
            }

            return Activator.GetObject(entr.ObjectType, entr.ObjectUrl);
        }

        private static void InitTypeCache() 
        {
            m_isInit = true;

            m_wellKnownTypes= new Hashtable();
            foreach (WellKnownClientTypeEntry entr in RemotingConfiguration.GetRegisteredWellKnownClientTypes()) 
            {
                if (entr.ObjectType == null)
                {
                    string msg = string.Format("Configured well-known client entry '{0}' could not be found", entr.ToString());
                    throw new RemotingException(msg);
                }
                m_wellKnownTypes.Add(entr.ObjectType, entr);
            }
        }
    }
}

C#远程访问通用类