mscorlib(4.0.0.0) API with additions
SByte.cs
4 using System.Security;
5 
6 namespace System
7 {
10  [CLSCompliant(false)]
11  [ComVisible(true)]
12  [__DynamicallyInvokable]
14  {
15  private sbyte m_value;
16 
18  [__DynamicallyInvokable]
19  public const sbyte MaxValue = 127;
20 
22  [__DynamicallyInvokable]
23  public const sbyte MinValue = -128;
24 
31  public int CompareTo(object obj)
32  {
33  if (obj == null)
34  {
35  return 1;
36  }
37  if (!(obj is sbyte))
38  {
39  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeSByte"));
40  }
41  return this - (sbyte)obj;
42  }
43 
47  [__DynamicallyInvokable]
48  public int CompareTo(sbyte value)
49  {
50  return this - value;
51  }
52 
57  [__DynamicallyInvokable]
58  public override bool Equals(object obj)
59  {
60  if (!(obj is sbyte))
61  {
62  return false;
63  }
64  return this == (sbyte)obj;
65  }
66 
71  [NonVersionable]
72  [__DynamicallyInvokable]
73  public bool Equals(sbyte obj)
74  {
75  return this == obj;
76  }
77 
80  [__DynamicallyInvokable]
81  public override int GetHashCode()
82  {
83  return this ^ (this << 8);
84  }
85 
88  [SecuritySafeCritical]
89  [__DynamicallyInvokable]
90  public override string ToString()
91  {
92  return Number.FormatInt32(this, null, NumberFormatInfo.CurrentInfo);
93  }
94 
98  [SecuritySafeCritical]
99  [__DynamicallyInvokable]
100  public string ToString(IFormatProvider provider)
101  {
102  return Number.FormatInt32(this, null, NumberFormatInfo.GetInstance(provider));
103  }
104 
110  [__DynamicallyInvokable]
111  public string ToString(string format)
112  {
113  return ToString(format, NumberFormatInfo.CurrentInfo);
114  }
115 
122  [__DynamicallyInvokable]
123  public string ToString(string format, IFormatProvider provider)
124  {
125  return ToString(format, NumberFormatInfo.GetInstance(provider));
126  }
127 
128  [SecuritySafeCritical]
129  private string ToString(string format, NumberFormatInfo info)
130  {
131  if (this < 0 && format != null && format.Length > 0 && (format[0] == 'X' || format[0] == 'x'))
132  {
133  uint value = (uint)(this & 0xFF);
134  return Number.FormatUInt32(value, format, info);
135  }
136  return Number.FormatInt32(this, format, info);
137  }
138 
148  [CLSCompliant(false)]
149  [__DynamicallyInvokable]
150  public static sbyte Parse(string s)
151  {
152  return Parse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
153  }
154 
169  [CLSCompliant(false)]
170  [__DynamicallyInvokable]
171  public static sbyte Parse(string s, NumberStyles style)
172  {
173  NumberFormatInfo.ValidateParseStyleInteger(style);
174  return Parse(s, style, NumberFormatInfo.CurrentInfo);
175  }
176 
187  [CLSCompliant(false)]
188  [__DynamicallyInvokable]
189  public static sbyte Parse(string s, IFormatProvider provider)
190  {
191  return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
192  }
193 
209  [CLSCompliant(false)]
210  [__DynamicallyInvokable]
211  public static sbyte Parse(string s, NumberStyles style, IFormatProvider provider)
212  {
213  NumberFormatInfo.ValidateParseStyleInteger(style);
214  return Parse(s, style, NumberFormatInfo.GetInstance(provider));
215  }
216 
217  private static sbyte Parse(string s, NumberStyles style, NumberFormatInfo info)
218  {
219  int num = 0;
220  try
221  {
222  num = Number.ParseInt32(s, style, info);
223  }
224  catch (OverflowException innerException)
225  {
226  throw new OverflowException(Environment.GetResourceString("Overflow_SByte"), innerException);
227  }
228  if ((style & NumberStyles.AllowHexSpecifier) != 0)
229  {
230  if (num < 0 || num > 255)
231  {
232  throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
233  }
234  return (sbyte)num;
235  }
236  if (num < -128 || num > 127)
237  {
238  throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
239  }
240  return (sbyte)num;
241  }
242 
248  [CLSCompliant(false)]
249  [__DynamicallyInvokable]
250  public static bool TryParse(string s, out sbyte result)
251  {
252  return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
253  }
254 
265  [CLSCompliant(false)]
266  [__DynamicallyInvokable]
267  public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out sbyte result)
268  {
269  NumberFormatInfo.ValidateParseStyleInteger(style);
270  return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
271  }
272 
273  private static bool TryParse(string s, NumberStyles style, NumberFormatInfo info, out sbyte result)
274  {
275  result = 0;
276  if (!Number.TryParseInt32(s, style, info, out int result2))
277  {
278  return false;
279  }
280  if ((style & NumberStyles.AllowHexSpecifier) != 0)
281  {
282  if (result2 < 0 || result2 > 255)
283  {
284  return false;
285  }
286  result = (sbyte)result2;
287  return true;
288  }
289  if (result2 < -128 || result2 > 127)
290  {
291  return false;
292  }
293  result = (sbyte)result2;
294  return true;
295  }
296 
300  {
301  return TypeCode.SByte;
302  }
303 
308  [__DynamicallyInvokable]
310  {
311  return Convert.ToBoolean(this);
312  }
313 
317  [__DynamicallyInvokable]
319  {
320  return Convert.ToChar(this);
321  }
322 
326  [__DynamicallyInvokable]
328  {
329  return this;
330  }
331 
335  [__DynamicallyInvokable]
337  {
338  return Convert.ToByte(this);
339  }
340 
344  [__DynamicallyInvokable]
346  {
347  return Convert.ToInt16(this);
348  }
349 
353  [__DynamicallyInvokable]
355  {
356  return Convert.ToUInt16(this);
357  }
358 
362  [__DynamicallyInvokable]
364  {
365  return this;
366  }
367 
371  [__DynamicallyInvokable]
373  {
374  return Convert.ToUInt32(this);
375  }
376 
380  [__DynamicallyInvokable]
382  {
383  return Convert.ToInt64(this);
384  }
385 
389  [__DynamicallyInvokable]
391  {
392  return Convert.ToUInt64(this);
393  }
394 
398  [__DynamicallyInvokable]
400  {
401  return Convert.ToSingle(this);
402  }
403 
407  [__DynamicallyInvokable]
409  {
410  return Convert.ToDouble(this);
411  }
412 
416  [__DynamicallyInvokable]
418  {
419  return Convert.ToDecimal(this);
420  }
421 
426  [__DynamicallyInvokable]
428  {
429  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "SByte", "DateTime"));
430  }
431 
436  [__DynamicallyInvokable]
437  object IConvertible.ToType(Type type, IFormatProvider provider)
438  {
439  return Convert.DefaultToType(this, type, provider);
440  }
441  }
442 }
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
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
double ToDouble(IFormatProvider provider)
Converts the value of this instance to an equivalent double-precision floating-point number using the...
string ToString(string format, IFormatProvider provider)
Converts the numeric value of this instance to its equivalent string representation using the specifi...
Definition: SByte.cs:123
static sbyte Parse(string s, IFormatProvider provider)
Converts the string representation of a number in a specified culture-specific format to its 8-bit si...
Definition: SByte.cs:189
string ToString(IFormatProvider provider)
Converts the numeric value of this instance to its equivalent string representation using the specifi...
Definition: SByte.cs:100
const sbyte MinValue
Represents the smallest possible value of T:System.SByte. This field is constant.
Definition: SByte.cs:23
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
TypeCode GetTypeCode()
Returns the T:System.TypeCode for value type T:System.SByte.
Definition: SByte.cs:299
Definition: __Canon.cs:3
The exception that is thrown for invalid casting or explicit conversion.
static sbyte Parse(string s)
Converts the string representation of a number to its 8-bit signed integer equivalent.
Definition: SByte.cs:150
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.
bool Equals(sbyte obj)
Returns a value indicating whether this instance is equal to a specified T:System....
Definition: SByte.cs:73
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
DateTime ToDateTime(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.DateTime using the specified culture-sp...
const sbyte MaxValue
Represents the largest possible value of T:System.SByte. This field is constant.
Definition: SByte.cs:19
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
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...
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....
override bool Equals(object obj)
Returns a value indicating whether this instance is equal to a specified object.
Definition: SByte.cs:58
static ushort ToUInt16(object value)
Converts the value of the specified object to a 16-bit unsigned integer.
Definition: Convert.cs:1707
string ToString(string format)
Converts the numeric value of this instance to its equivalent string representation,...
Definition: SByte.cs:111
object ToType(Type conversionType, IFormatProvider provider)
Converts the value of this instance to an T:System.Object of the specified T:System....
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
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
Represents an 8-bit signed integer.
Definition: SByte.cs:13
static sbyte Parse(string s, NumberStyles style, IFormatProvider provider)
Converts the string representation of a number that is in a specified style and culture-specific form...
Definition: SByte.cs:211
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: SByte.cs:81
static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out sbyte result)
Tries to convert the string representation of a number in a specified style and culture-specific form...
Definition: SByte.cs:267
override string ToString()
Converts the numeric value of this instance to its equivalent string representation.
Definition: SByte.cs:90
static byte ToByte(object value)
Converts the value of the specified object to an 8-bit unsigned integer.
Definition: Convert.cs:1186
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, out sbyte result)
Tries to convert the string representation of a number to its T:System.SByte equivalent,...
Definition: SByte.cs:250
Specifies that the class can be serialized.
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
int CompareTo(object obj)
Compares this instance to a specified object and returns an indication of their relative values.
Definition: SByte.cs:31
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 sbyte Parse(string s, NumberStyles style)
Converts the string representation of a number in a specified style to its 8-bit signed integer equiv...
Definition: SByte.cs:171
Provides functionality to format the value of an object into a string representation.
Definition: IFormattable.cs:8
uint ToUInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified cult...
int CompareTo(sbyte value)
Compares this instance to a specified 8-bit signed integer and returns an indication of their relativ...
Definition: SByte.cs:48
Provides culture-specific information for formatting and parsing numeric values.