mscorlib(4.0.0.0) API with additions
Byte.cs
4 using System.Security;
5 
6 namespace System
7 {
10  [ComVisible(true)]
11  [__DynamicallyInvokable]
13  {
14  private byte m_value;
15 
17  [__DynamicallyInvokable]
18  public const byte MaxValue = 255;
19 
21  [__DynamicallyInvokable]
22  public const byte MinValue = 0;
23 
30  public int CompareTo(object value)
31  {
32  if (value == null)
33  {
34  return 1;
35  }
36  if (!(value is byte))
37  {
38  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeByte"));
39  }
40  return this - (byte)value;
41  }
42 
46  [__DynamicallyInvokable]
47  public int CompareTo(byte value)
48  {
49  return this - value;
50  }
51 
56  [__DynamicallyInvokable]
57  public override bool Equals(object obj)
58  {
59  if (!(obj is byte))
60  {
61  return false;
62  }
63  return this == (byte)obj;
64  }
65 
70  [NonVersionable]
71  [__DynamicallyInvokable]
72  public bool Equals(byte obj)
73  {
74  return this == obj;
75  }
76 
79  [__DynamicallyInvokable]
80  public override int GetHashCode()
81  {
82  return this;
83  }
84 
94  [__DynamicallyInvokable]
95  public static byte Parse(string s)
96  {
97  return Parse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
98  }
99 
114  [__DynamicallyInvokable]
115  public static byte Parse(string s, NumberStyles style)
116  {
117  NumberFormatInfo.ValidateParseStyleInteger(style);
118  return Parse(s, style, NumberFormatInfo.CurrentInfo);
119  }
120 
131  [__DynamicallyInvokable]
132  public static byte Parse(string s, IFormatProvider provider)
133  {
134  return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
135  }
136 
152  [__DynamicallyInvokable]
153  public static byte Parse(string s, NumberStyles style, IFormatProvider provider)
154  {
155  NumberFormatInfo.ValidateParseStyleInteger(style);
156  return Parse(s, style, NumberFormatInfo.GetInstance(provider));
157  }
158 
159  private static byte Parse(string s, NumberStyles style, NumberFormatInfo info)
160  {
161  int num = 0;
162  try
163  {
164  num = Number.ParseInt32(s, style, info);
165  }
166  catch (OverflowException innerException)
167  {
168  throw new OverflowException(Environment.GetResourceString("Overflow_Byte"), innerException);
169  }
170  if (num < 0 || num > 255)
171  {
172  throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
173  }
174  return (byte)num;
175  }
176 
182  [__DynamicallyInvokable]
183  public static bool TryParse(string s, out byte result)
184  {
185  return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
186  }
187 
198  [__DynamicallyInvokable]
199  public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out byte result)
200  {
201  NumberFormatInfo.ValidateParseStyleInteger(style);
202  return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
203  }
204 
205  private static bool TryParse(string s, NumberStyles style, NumberFormatInfo info, out byte result)
206  {
207  result = 0;
208  if (!Number.TryParseInt32(s, style, info, out int result2))
209  {
210  return false;
211  }
212  if (result2 < 0 || result2 > 255)
213  {
214  return false;
215  }
216  result = (byte)result2;
217  return true;
218  }
219 
222  [SecuritySafeCritical]
223  [__DynamicallyInvokable]
224  public override string ToString()
225  {
226  return Number.FormatInt32(this, null, NumberFormatInfo.CurrentInfo);
227  }
228 
234  [SecuritySafeCritical]
235  [__DynamicallyInvokable]
236  public string ToString(string format)
237  {
238  return Number.FormatInt32(this, format, NumberFormatInfo.CurrentInfo);
239  }
240 
244  [SecuritySafeCritical]
245  [__DynamicallyInvokable]
246  public string ToString(IFormatProvider provider)
247  {
248  return Number.FormatInt32(this, null, NumberFormatInfo.GetInstance(provider));
249  }
250 
257  [SecuritySafeCritical]
258  [__DynamicallyInvokable]
259  public string ToString(string format, IFormatProvider provider)
260  {
261  return Number.FormatInt32(this, format, NumberFormatInfo.GetInstance(provider));
262  }
263 
267  {
268  return TypeCode.Byte;
269  }
270 
275  [__DynamicallyInvokable]
277  {
278  return Convert.ToBoolean(this);
279  }
280 
284  [__DynamicallyInvokable]
286  {
287  return Convert.ToChar(this);
288  }
289 
293  [__DynamicallyInvokable]
295  {
296  return Convert.ToSByte(this);
297  }
298 
302  [__DynamicallyInvokable]
304  {
305  return this;
306  }
307 
311  [__DynamicallyInvokable]
313  {
314  return Convert.ToInt16(this);
315  }
316 
320  [__DynamicallyInvokable]
322  {
323  return Convert.ToUInt16(this);
324  }
325 
329  [__DynamicallyInvokable]
331  {
332  return Convert.ToInt32(this);
333  }
334 
338  [__DynamicallyInvokable]
340  {
341  return Convert.ToUInt32(this);
342  }
343 
347  [__DynamicallyInvokable]
349  {
350  return Convert.ToInt64(this);
351  }
352 
356  [__DynamicallyInvokable]
358  {
359  return Convert.ToUInt64(this);
360  }
361 
365  [__DynamicallyInvokable]
367  {
368  return Convert.ToSingle(this);
369  }
370 
374  [__DynamicallyInvokable]
376  {
377  return Convert.ToDouble(this);
378  }
379 
383  [__DynamicallyInvokable]
385  {
386  return Convert.ToDecimal(this);
387  }
388 
393  [__DynamicallyInvokable]
395  {
396  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "Byte", "DateTime"));
397  }
398 
406  [__DynamicallyInvokable]
407  object IConvertible.ToType(Type type, IFormatProvider provider)
408  {
409  return Convert.DefaultToType(this, type, provider);
410  }
411  }
412 }
float ToSingle(IFormatProvider provider)
Converts the value of this instance to an equivalent single-precision floating-point number using the...
Converts a base data type to another base data type.
Definition: Convert.cs:10
override string ToString()
Converts the value of the current T:System.Byte object to its equivalent string representation.
Definition: Byte.cs:224
static long ToInt64(object value)
Converts the value of the specified object to a 64-bit signed integer.
Definition: Convert.cs:2506
static double ToDouble(object value)
Converts the value of the specified object to a double-precision floating-point number.
Definition: Convert.cs:3189
string ToString(IFormatProvider provider)
Converts the numeric value of the current T:System.Byte object to its equivalent string representatio...
Definition: Byte.cs:246
static byte Parse(string s)
Converts the string representation of a number to its T:System.Byte equivalent.
Definition: Byte.cs:95
override bool Equals(object obj)
Returns a value indicating whether this instance is equal to a specified object.
Definition: Byte.cs:57
double ToDouble(IFormatProvider provider)
Converts the value of this instance to an equivalent double-precision floating-point number using the...
bool ToBoolean(IFormatProvider provider)
Converts the value of this instance to an equivalent Boolean value using the specified culture-specif...
TypeCode
Specifies the type of an object.
Definition: TypeCode.cs:9
static float ToSingle(object value)
Converts the value of the specified object to a single-precision floating-point number.
Definition: Convert.cs:2982
int CompareTo(object value)
Compares this instance to a specified object and returns an indication of their relative values.
Definition: Byte.cs:30
Definition: __Canon.cs:3
The exception that is thrown for invalid casting or explicit conversion.
char ToChar(IFormatProvider provider)
Converts the value of this instance to an equivalent Unicode character using the specified culture-sp...
Provides a mechanism for retrieving an object to control formatting.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
static byte Parse(string s, NumberStyles style, IFormatProvider provider)
Converts the string representation of a number in a specified style and culture-specific format to it...
Definition: Byte.cs:153
DateTime ToDateTime(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.DateTime using the specified culture-sp...
const byte MinValue
Represents the smallest possible value of a T:System.Byte. This field is constant.
Definition: Byte.cs:22
static NumberFormatInfo CurrentInfo
Gets a read-only T:System.Globalization.NumberFormatInfo that formats values based on the current cul...
sbyte ToSByte(IFormatProvider provider)
Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture...
Defines a generalized type-specific comparison method that a value type or class implements to order ...
Definition: IComparable.cs:8
NumberStyles
Determines the styles permitted in numeric string arguments that are passed to the Parse and TryParse...
Definition: NumberStyles.cs:10
static char ToChar(object value)
Converts the value of the specified object to a Unicode character.
Definition: Convert.cs:670
string ToString(string format, IFormatProvider provider)
Converts the value of the current T:System.Byte object to its equivalent string representation using ...
Definition: Byte.cs:259
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
static bool ToBoolean(object value)
Converts the value of a specified object to an equivalent Boolean value.
Definition: Convert.cs:457
decimal ToDecimal(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.Decimal number using the specified cult...
TypeCode GetTypeCode()
Returns the T:System.TypeCode for value type T:System.Byte.
Definition: Byte.cs:266
int ToInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit signed integer using the specified cultur...
static NumberFormatInfo GetInstance(IFormatProvider formatProvider)
Gets the T:System.Globalization.NumberFormatInfo associated with the specified T:System....
const byte MaxValue
Represents the largest possible value of a T:System.Byte. This field is constant.
Definition: Byte.cs:18
static ushort ToUInt16(object value)
Converts the value of the specified object to a 16-bit unsigned integer.
Definition: Convert.cs:1707
object ToType(Type conversionType, IFormatProvider provider)
Converts the value of this instance to an T:System.Object of the specified T:System....
static sbyte ToSByte(object value)
Converts the value of the specified object to an 8-bit signed integer.
Definition: Convert.cs:909
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
int CompareTo(byte value)
Compares this instance to a specified 8-bit unsigned integer and returns an indication of their relat...
Definition: Byte.cs:47
ushort ToUInt16(IFormatProvider provider)
Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified cult...
static uint ToUInt32(object value)
Converts the value of the specified object to a 32-bit unsigned integer.
Definition: Convert.cs:2235
short ToInt16(IFormatProvider provider)
Converts the value of this instance to an equivalent 16-bit signed integer using the specified cultur...
static decimal ToDecimal(object value)
Converts the value of the specified object to an equivalent decimal number.
Definition: Convert.cs:3394
long ToInt64(IFormatProvider provider)
Converts the value of this instance to an equivalent 64-bit signed integer using the specified cultur...
The exception that is thrown when one of the arguments provided to a method is not valid.
override int GetHashCode()
Returns the hash code for this instance.
Definition: Byte.cs:80
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: IEquatable.cs:6
static short ToInt16(object value)
Converts the value of the specified object to a 16-bit signed integer.
Definition: Convert.cs:1452
static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out byte result)
Converts the string representation of a number in a specified style and culture-specific format to it...
Definition: Byte.cs:199
Specifies that the class can be serialized.
static bool TryParse(string s, out byte result)
Tries to convert the string representation of a number to its T:System.Byte equivalent,...
Definition: Byte.cs:183
ulong ToUInt64(IFormatProvider provider)
Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified cult...
static ulong ToUInt64(object value)
Converts the value of the specified object to a 64-bit unsigned integer.
Definition: Convert.cs:2727
static int ToInt32(object value)
Converts the value of the specified object to a 32-bit signed integer.
Definition: Convert.cs:1974
byte ToByte(IFormatProvider provider)
Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified cultu...
Defines methods that convert the value of the implementing reference or value type to a common langua...
Definition: IConvertible.cs:9
static byte Parse(string s, NumberStyles style)
Converts the string representation of a number in a specified style to its T:System....
Definition: Byte.cs:115
string ToString(string format)
Converts the value of the current T:System.Byte object to its equivalent string representation using ...
Definition: Byte.cs:236
Provides functionality to format the value of an object into a string representation.
Definition: IFormattable.cs:8
Represents an 8-bit unsigned integer.
Definition: Byte.cs:12
bool Equals(byte obj)
Returns a value indicating whether this instance and a specified T:System.Byte object represent the s...
Definition: Byte.cs:72
static byte Parse(string s, IFormatProvider provider)
Converts the string representation of a number in a specified culture-specific format to its T:System...
Definition: Byte.cs:132
uint ToUInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified cult...
Provides culture-specific information for formatting and parsing numeric values.