Encodes the specified value, returning the result as a byte array. - CSharp System

CSharp examples for System:Byte

Description

Encodes the specified value, returning the result as a byte array.

Demo Code


using System.IO;/* w w  w.  ja  va 2 s.c  om*/
using System.Diagnostics;
using System;

public class Main{
        public static void Encode(Stream stream, String val, int maxSize)
        {
            byte[] buf = new byte[maxSize];
            if (val != null)
            {
                System.Text.Encoding.ASCII.GetBytes(val).CopyTo(buf, 0);
            }
            stream.Write(buf, 0, buf.Length);
        }
        /// <summary> 
        /// Encodes the specified value, returning the result as a byte array.
        /// </summary>
        /// <param name="parameterValue">the value to Encode
        /// </param>
        /// <returns> 
        /// a byte array containing the encoded value
        /// An array of bytes with length 2.
        /// </returns>
        public static byte[] Encode(String val)
        {
            byte[] buf = System.Text.Encoding.ASCII.GetBytes(val);
            return buf;
        }
}

Related Tutorials