本文整理匯總了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);
}
}
輸出:
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