C# | SByte Struct Fields
Last Updated :
02 May, 2019
In C#, Sbyte Struct comes under the System namespace which represents an 8-bit signed integer. The SByte value type represents integers with values ranging from -128 to +127. There are the two fields in the System.SByte Struct as follows:
- SByte.MaxValue Field
- SByte.MinValue Field
SByte.MaxValue Field
This is a constant field which represents the largest possible value(127) of SByte.
Syntax:
public const sbyte MaxValue = 127;
Example:
using System;
class Max_Geeks {
static public void Main()
{
long lValue = 128;
sbyte sbValue;
if (lValue <= sbyte .MaxValue) {
sbValue = ( sbyte )lValue;
Console.WriteLine( "Converted long integer value to {0}." , sbValue);
}
else {
Console.WriteLine( "Conversion is not Possible" );
}
}
}
|
Output:
Conversion is not Possible
SByte.MinValue Field
This is a constant field which represents the smallest possible value(-128) of SByte.
Syntax:
public const sbyte MinValue = -128;
Example:
using System;
class Min_Geeks {
static public void Main()
{
long lValue = -128;
sbyte sbValue;
if (lValue >= sbyte .MinValue) {
sbValue = ( sbyte )lValue;
Console.WriteLine( "Converted long integer value to {0}" , sbValue);
}
else {
Console.WriteLine( "Conversion is not Possible" );
}
}
}
|
Output:
Converted long integer value to -128
References:
Share your thoughts in the comments
Please Login to comment...