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


C# Base64FormattingOptions枚舉代碼示例

本文整理匯總了C#中System.Base64FormattingOptions枚舉的典型用法代碼示例。如果您正苦於以下問題:C# Base64FormattingOptions枚舉的具體用法?C# Base64FormattingOptions怎麽用?C# Base64FormattingOptions使用的例子?那麽, 這裏精選的枚舉代碼示例或許可以為您提供幫助。


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

示例1: Main

//引入命名空間
using System;

public class Example
{
   public static void Main()
   {
       // Define a byte array.
       var bytes = new byte[100];
       int originalTotal = 0;
       for (int ctr = 0; ctr <= bytes.GetUpperBound(0); ctr++) {
          bytes[ctr] = (byte)(ctr + 1);
          originalTotal += bytes[ctr];
       }
       // Display summary information about the array.
       Console.WriteLine("The original byte array:");
       Console.WriteLine("   Total elements: {0}", bytes.Length);
       Console.WriteLine("   Length of String Representation: {0}",
                         BitConverter.ToString(bytes).Length);
       Console.WriteLine("   Sum of elements: {0:N0}", originalTotal);                  
       Console.WriteLine();
       
       // Convert the array to a base 64 string.
       string s = Convert.ToBase64String(bytes, 
                                         Base64FormattingOptions.InsertLineBreaks);
       Console.WriteLine("The base 64 string:\n   {0}\n", s);
       
       // Restore the byte array.
       Byte[] newBytes = Convert.FromBase64String(s);
       int newTotal = 0;
       foreach (var newByte in newBytes)
          newTotal += newByte;

       // Display summary information about the restored array.
       Console.WriteLine("   Total elements: {0}", newBytes.Length);
       Console.WriteLine("   Length of String Representation: {0}",
                         BitConverter.ToString(newBytes).Length);
       Console.WriteLine("   Sum of elements: {0:N0}", newTotal);                  
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:40,代碼來源:Base64FormattingOptions

輸出:

The original byte array:
Total elements: 100
Length of String Representation: 299
Sum of elements: 5,050

The base 64 string:
AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5
Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZA==

Total elements: 100
Length of String Representation: 299
Sum of elements: 5,050


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