當前位置: 首頁>>代碼示例>>C#>>正文


C# Binary.ToArray方法代碼示例

本文整理匯總了C#中Binary.ToArray方法的典型用法代碼示例。如果您正苦於以下問題:C# Binary.ToArray方法的具體用法?C# Binary.ToArray怎麽用?C# Binary.ToArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Binary的用法示例。


在下文中一共展示了Binary.ToArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ToString

        /// <summary>
        /// Converts binary value to string.
        /// </summary>
        /// <param name="version">Binary version number.</param>
        /// <returns>Base64 version number.</returns>
        public static string ToString(Binary version)
        {
            if (version == null)
                return null;

            return Convert.ToBase64String(version.ToArray());
        }
開發者ID:ronymaychan,項目名稱:demos,代碼行數:12,代碼來源:VersionConverter.cs

示例2: ConvertBinaryToItemId

        private string ConvertBinaryToItemId(Binary binary)
        {
            byte[] binaryString = binary.ToArray();

            // if the original encoding was ASCII
            string x = Encoding.ASCII.GetString(binaryString);

            // if the original encoding was UTF-8
            string y = Encoding.UTF8.GetString(binaryString);

            // if the original encoding was UTF-16
            string z = Encoding.Unicode.GetString(binaryString);

            string strBinary = binary.ToString();
            StringBuilder result = new StringBuilder(strBinary.Length / 8 + 1);

            // TODO: check all 1's or 0's... Will throw otherwise

            int mod4Len = binary.Length % 8;
            if (mod4Len != 0)
            {
                // pad to length multiple of 8
                strBinary = strBinary.PadLeft(((strBinary.Length / 8) + 1) * 8, '0');
            }

            for (int i = 0; i < binary.Length; i += 8)
            {
                string eightBits = strBinary.Substring(i, 8);
                result.AppendFormat("{0:X2}", System.Convert.ToByte(eightBits, 2));
            }

            return result.ToString();
        }
開發者ID:Velir,項目名稱:Sitecore-Analytics,代碼行數:33,代碼來源:TestVariationGrouping.cs

示例3: CanBeEnumerated

        public void CanBeEnumerated()
        {
            var binary = new Binary(new byte[] { 10, 20 });

            var array = binary.ToArray();
            Assert.AreEqual(2,array.Length);
            Assert.AreEqual(10, array[0]);
            Assert.AreEqual(20, array[1]);
        }
開發者ID:gaoninggn,項目名稱:mongodb-csharp,代碼行數:9,代碼來源:TestBinary.cs

示例4: BinaryAddition

        public int BinaryAddition(Binary a, Binary b)
        {
            Binary c = new Binary(new Byte[a.Length + 1]);
            int key = 0;
            byte[] byteArray = c.ToArray ();
            for (int i = a.Length - 1; i >= 0; i--)
            {
                byte sum = (byte)((byte)(a.ToArray () [i]) + (byte)(b.ToArray () [i]) + (byte)key);
                byteArray[i + 1] = (byte)(sum % 2);
                key = (int)(sum / 2);
            }
            byteArray [0] = (byte)key;
            c = byteArray;

            string x = null;
            for (int i = 0; i < c.Length; i++)
            {
                x += c.ToArray () [i];
            }
            return Convert.ToInt32 (x, 2);
        }
開發者ID:Zerophase,項目名稱:Algorithms,代碼行數:21,代碼來源:Addition.cs

示例5: BinaryToImage

        /// <summary>
        /// 將二進位資料轉換為 Bitmap
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Bitmap BinaryToImage(Binary data)
        {
            Bitmap image = null;

            if (data != null)
            {
                try
                {
                    using (MemoryStream ms = new MemoryStream(data.ToArray()))
                    {
                        image = new Bitmap(Image.FromStream(ms));
                    }
                }
                catch (IOException ex)
                {
                    Hanbo.Log.LogManager.Error(ex);
                }
            }
            return image;
        }
開發者ID:Joncash,項目名稱:HanboAOMClassLibrary,代碼行數:25,代碼來源:ImageHelper.cs

示例6: ToDateTimeOffset

		// Other Types
		//
		/// <summary>Converts the value from <c>Binary</c> to an equivalent <c>DateTimeOffset</c> value.</summary>
		public static DateTimeOffset ToDateTimeOffset(Binary          p) { return p == null || p.Length == 0 ? DateTimeOffset.MinValue : new DateTimeOffset(ToDateTime(p.ToArray())); }
開發者ID:titolarz,項目名稱:bltoolkit,代碼行數:4,代碼來源:Convert.generated.cs

示例7: ToSqlDateTime

		// Other Types
		//
		/// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlDateTime</c> value.</summary>
		public static SqlDateTime ToSqlDateTime(Binary          p) { return p == null || p.Length == 0 ? SqlDateTime.Null : DateTime.FromBinary(ToInt64(p.ToArray()));   }
開發者ID:titolarz,項目名稱:bltoolkit,代碼行數:4,代碼來源:Convert.generated.cs

示例8: ToNullableDateTimeOffset

		// Other Types
		//
		/// <summary>Converts the value from <c>Binary</c> to an equivalent <c>DateTimeOffset?</c> value.</summary>
		public static DateTimeOffset? ToNullableDateTimeOffset(Binary         p) { return p == null || p.Length == 0 ? (DateTimeOffset?)null : new DateTimeOffset?(ToDateTime(p.ToArray())); }
開發者ID:titolarz,項目名稱:bltoolkit,代碼行數:4,代碼來源:Convert.generated.cs

示例9: ToBoolean

		// Other Types
		//
		/// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Boolean</c> value.</summary>
		public static Boolean ToBoolean(Binary     p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Boolean : BitConverter.ToBoolean(p.ToArray(), 0); }
開發者ID:titolarz,項目名稱:bltoolkit,代碼行數:4,代碼來源:Convert.generated.cs

示例10: ToStream

		// Other Types
		//
		/// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Stream</c> value.</summary>
		public static Stream ToStream(Binary    p) { return p == null ? Stream.Null : new MemoryStream(p.ToArray());            }
開發者ID:titolarz,項目名稱:bltoolkit,代碼行數:4,代碼來源:Convert.generated.cs

示例11: ToSqlXml

		// Other Types
		//
		/// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlXml</c> value.</summary>
		public static SqlXml ToSqlXml(Binary      p) { return p == null ? SqlXml.Null : new SqlXml(new MemoryStream(p.ToArray()));                             }
開發者ID:titolarz,項目名稱:bltoolkit,代碼行數:4,代碼來源:Convert.generated.cs

示例12: ToSqlSingle

		// Other Types
		//
		/// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlSingle</c> value.</summary>
		public static SqlSingle ToSqlSingle(Binary     p) { return p == null || p.Length == 0 ? SqlSingle.Null : BitConverter.ToSingle(p.ToArray(), 0); }
開發者ID:titolarz,項目名稱:bltoolkit,代碼行數:4,代碼來源:Convert.generated.cs

示例13: ToDateTime

		// Other Types
		//
		/// <summary>Converts the value from <c>Binary</c> to an equivalent <c>DateTime</c> value.</summary>
		public static DateTime ToDateTime(Binary          p) { return p == null || p.Length == 0 ? Configuration.NullableValues.DateTime : DateTime.FromBinary(ToInt64(p.ToArray()));   }
開發者ID:titolarz,項目名稱:bltoolkit,代碼行數:4,代碼來源:Convert.generated.cs

示例14: ToNullableTimeSpan

		// Other Types
		//
		/// <summary>Converts the value from <c>Binary</c> to an equivalent <c>TimeSpan?</c> value.</summary>
		public static TimeSpan? ToNullableTimeSpan(Binary          p) { return p == null || p.Length == 0? (TimeSpan?)null : TimeSpan.FromTicks(ToInt64(p.ToArray())); }
開發者ID:titolarz,項目名稱:bltoolkit,代碼行數:4,代碼來源:Convert.generated.cs

示例15: ToNullableSingle

		// Other Types
		//
		/// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Single?</c> value.</summary>
		public static Single? ToNullableSingle(Binary     p) { return p == null || p.Length == 0 ? (Single?)null : BitConverter.ToSingle(p.ToArray(), 0); }
開發者ID:titolarz,項目名稱:bltoolkit,代碼行數:4,代碼來源:Convert.generated.cs


注:本文中的Binary.ToArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。