Microsoft.SqlServer.TDS.TDSUtilities.ReadString C# (CSharp) Method

ReadString() static private method

Read string from the packet
static private ReadString ( Stream source, ushort length ) : string
source Stream
length ushort
return string
        internal static string ReadString(Stream source, ushort length)
        {
            // Check if any data will be read
            if (length == 0)
            {
                // Instead of returning an empty string later we just return NULL
                return null;
            }

            // Allocate buffer
            byte[] byteString = new byte[length];

            // Read into a byte buffer
            source.Read(byteString, 0, byteString.Length);

            // Convert
            return Encoding.Unicode.GetString(byteString, 0, byteString.Length);
        }