Convert byte to string with culture-specific format in CSharp

Description

The following code shows how to convert byte to string with culture-specific format.

Example


/*from www .  j  av  a 2s .c  om*/
using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      NumberFormatInfo nfi = new NumberFormatInfo();
      nfi.NegativeSign = "~";

      sbyte[] bytes = { -122, 17, 124 };

      foreach (sbyte value in bytes){
         Console.WriteLine(value.ToString(nfi));
      }
      Console.WriteLine("Using the invariant culture:");
      foreach (sbyte value in bytes){
         Console.WriteLine(value.ToString(NumberFormatInfo.InvariantInfo));
      }   
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var