本文整理汇总了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