System::Byte class

Byte class

Contains methods to work with the unsigned 8-bit integer.

class Byte

Methods

MethodDescription
static Parse(const String&)Converts the specified string containing the string representation of a number to the equivalent 8-bit unsigned integer.
static Parse(const String&, const SharedPtr<IFormatProvider>&)Converts the specified string containing the string representation of a number to the equivalent 8-bit unsigned integer using the provided formatting information.
static Parse(const String&, const SharedPtr<Globalization::CultureInfo>&)
static Parse(const String&, const SharedPtr<Globalization::NumberFormatInfo>&)
static Parse(const String&, std::nullptr_t)
static Parse(const String&, Globalization::NumberStyles, const SharedPtr<IFormatProvider>&)Converts the specified string containing the string representation of a number to the equivalent 8-bit unsigned integer using the provided formatting information and number style.
static Parse(const String&, Globalization::NumberStyles, const SharedPtr<Globalization::CultureInfo>&)
static Parse(const String&, Globalization::NumberStyles, const SharedPtr<Globalization::NumberFormatInfo>&)
static Parse(const String&, Globalization::NumberStyles, std::nullptr_t)
static TryParse(const String&, uint8_t&)Converts the specified string containing the string representation of a number to the equivalent 8-bit unsigned integer.
static TryParse(const String&, Globalization::NumberStyles, const SharedPtr<IFormatProvider>&, uint8_t&)Converts the specified string containing the string representation of a number to the equivalent 8-bit unsigned integer using the provided formatting information and number style.
static TryParse(const String&, Globalization::NumberStyles, const SharedPtr<Globalization::CultureInfo>&, uint8_t&)
static TryParse(const String&, Globalization::NumberStyles, const SharedPtr<Globalization::NumberFormatInfo>&, uint8_t&)
static TryParse(const String&, Globalization::NumberStyles, std::nullptr_t, uint8_t&)

Fields

FieldDescription
static constexpr MaxValueLargest possible value.
static constexpr MinValueSmallest possible value.

Remarks

#include <system/byte.h>

using namespace System;

int main()
{
  auto b1 = Byte::Parse(u"123");
  std::cout << static_cast<uint32_t>(b1) << std::endl;

  try
  {
    auto b2 = Byte::Parse(u"345");
    std::cout << static_cast<uint32_t>(b2) << std::endl;
  }
  catch (const OverflowException &ex)
  {
    std::cerr << ex.what() << std::endl;
  }

  uint8_t b3 = 0;
  if (Byte::TryParse(u"10", b3))
  {
    std::cout << static_cast<uint32_t>(b3) << std::endl;
  }
  else
  {
    std::cerr << "Something went wrong." << std::endl;
  }

  return 0;
}
/*
This code example produces the following output:
123
System::OverflowException: Value was either too large or too small for an UInt8
10
*/

See Also