Byte.cs :  » Development » NExcel » NExcelUtils » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » NExcel 
NExcel » NExcelUtils » Byte.cs
using System;

namespace NExcelUtils{
  /// <summary>
  /// Byte and SByte utils.
  /// </summary>
  internal class Byte
  {
    private Byte()
    {
    }


    /// <summary>
    /// Converts an array of sbytes to an array of bytes
    /// </summary>
    /// <param name="sbyteArray">The array of sbytes to be converted</param>
    /// <returns>The new array of bytes</returns>
    public static byte[] ToByteArray(sbyte[] sbyteArray)
    {
      byte[] byteArray = new byte[sbyteArray.Length];
      for(int index=0; index < sbyteArray.Length; index++)
        byteArray[index] = (byte) sbyteArray[index];
      return byteArray;
    }


    /// <summary>
    /// Converts a string to an array of bytes
    /// </summary>
    /// <param name="sourceString">The string to be converted</param>
    /// <returns>The new array of bytes</returns>
    public static byte[] ToByteArray(string sourceString)
    {
      byte[] byteArray = new byte[sourceString.Length];
      for (int index=0; index < sourceString.Length; index++)
        byteArray[index] = (byte) sourceString[index];
      return byteArray;
    }

    /// <summary>
    /// Converts a array of object-type instances to a byte-type array.
    /// </summary>
    /// <param name="tempObjectArray">Array to convert.</param>
    /// <returns>An array of byte type elements.</returns>
    public static byte[] ToByteArray(object[] tempObjectArray)
    {
      byte[] byteArray = new byte[tempObjectArray.Length];
      for (int index = 0; index < tempObjectArray.Length; index++)
        byteArray[index] = (byte)tempObjectArray[index];
      return byteArray;
    }

    /// <summary>
    /// Receives a byte array and returns it transformed in an sbyte array
    /// </summary>
    /// <param name="byteArray">Byte array to process</param>
    /// <returns>The transformed array</returns>
    public static sbyte[] ToSByteArray(byte[] byteArray)
    {
      sbyte[] sbyteArray = new sbyte[byteArray.Length];
      for(int index=0; index < byteArray.Length; index++)
        sbyteArray[index] = (sbyte) byteArray[index];
      return sbyteArray;
    }



    /// <summary>
    /// Converts an array of sbytes to an array of chars
    /// </summary>
    /// <param name="sByteArray">The array of sbytes to convert</param>
    /// <returns>The new array of chars</returns>
    public static char[] ToCharArray(sbyte[] sByteArray) 
    {
      char[] charArray = new char[sByteArray.Length];     
      sByteArray.CopyTo(charArray, 0);
      return charArray;
    }

    /// <summary>
    /// Converts an array of bytes to an array of chars
    /// </summary>
    /// <param name="byteArray">The array of bytes to convert</param>
    /// <returns>The new array of chars</returns>
    public static char[] ToCharArray(byte[] byteArray) 
    {
      char[] charArray = new char[byteArray.Length];     
      byteArray.CopyTo(charArray, 0);
      return charArray;
    }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.