System.Data.SqlTypes.SqlString.GetNonUnicodeBytes C# (CSharp) Method

GetNonUnicodeBytes() public method

public GetNonUnicodeBytes ( ) : byte[]
return byte[]
        public byte[] GetNonUnicodeBytes()
        {
            if (IsNull)
                return null;

            // Get the CultureInfo
            CultureInfo culInfo = new CultureInfo(_lcid);

            Encoding cpe = System.Text.Encoding.GetEncoding(culInfo.TextInfo.ANSICodePage);
            return cpe.GetBytes(_value);
        }

Usage Example

                public void Create()
                {

                        // SqlString (String)
                        SqlString  TestString = new SqlString ("Test");
                        AssertEquals ("#A01", "Test", TestString.Value);

                        // SqlString (String, int)
                        TestString = new SqlString ("Test", 2057);
                        AssertEquals ("#A02", 2057, TestString.LCID);

                        // SqlString (int, SqlCompareOptions, byte[])
                        TestString = new SqlString (2057,
                                                    SqlCompareOptions.BinarySort|SqlCompareOptions.IgnoreCase,
                                                    new byte [2] {123, 221});
                        AssertEquals ("#A03", 2057, TestString.CompareInfo.LCID);
                        
                        // SqlString(string, int, SqlCompareOptions)
                        TestString = new SqlString ("Test", 2057, SqlCompareOptions.IgnoreNonSpace);
                        Assert ("#A04", !TestString.IsNull);
                        
                        // SqlString (int, SqlCompareOptions, byte[], bool)
                        TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [4] {100, 100, 200, 45}, true);
                        AssertEquals ("#A05", (byte)63, TestString.GetNonUnicodeBytes () [0]);
                        TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, false);
                        AssertEquals ("#A06", (String)"qd", TestString.Value);
                        
                        // SqlString (int, SqlCompareOptions, byte[], int, int)
                        TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, 0, 2);
                        Assert ("#A07", !TestString.IsNull);

                        // SqlString (int, SqlCompareOptions, byte[], int, int, bool)
                        TestString = new SqlString (2057, SqlCompareOptions.IgnoreCase, new byte [3] {100, 111, 50}, 1, 2, false);
                        AssertEquals ("#A08", "o2", TestString.Value);
                        TestString = new SqlString (2057, SqlCompareOptions.IgnoreCase, new byte [3] {123, 111, 222}, 1, 2, true);
                        Assert ("#A09", !TestString.IsNull);                        
                }