当前位置: 首页>>代码示例>>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;未经允许,请勿转载。