C# | SByte Struct Fields

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:

  1. SByte.MaxValue Field
  2. 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the SByte.MaxValue
// Field by checking whether the given +ve long
// value can be converted to sbyte value or not
using System;
  
class Max_Geeks {
  
    // Main method
    static public void Main()
    {
  
        // Only taking +ve values
        long lValue = 128;
        sbyte sbValue;
  
        // Using the MaxValue Field to check
        // whether the conversion is Possible
        // or not for +ve values only
        if (lValue <= sbyte.MaxValue) {
  
            // Type conversion from long to sbyte
            sbValue = (sbyte)lValue;
  
            Console.WriteLine("Converted long integer value to {0}.", sbValue);
        }
  
        else {
            Console.WriteLine("Conversion is not Possible");
        }
    }
}

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the SByte.Min Value
// Field by checking whether the given -ve long
// value can be converted to sbyte value or not
using System;
  
class Min_Geeks {
  
    // Main method
    static public void Main()
    {
  
        // Only taking -ve values
        long lValue = -128;
        sbyte sbValue;
  
        // Using the MinValue Field to check
        // whether the conversion is Possible
        // or not for -ve values only
        if (lValue >= sbyte.MinValue) {
  
            // Type conversion from long to sbyte
            sbValue = (sbyte)lValue;
  
            Console.WriteLine("Converted long integer value to {0}", sbValue);
        }
  
        else {
            Console.WriteLine("Conversion is not Possible");
        }
    }
}

chevron_right


Output:

Converted long integer value to -128

References:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.