Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
sbyte Keyword in C#
Next article icon

C# | SByte Struct Fields

Last Updated : 02 May, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report

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:




// 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");
        }
    }
}
 
 

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:




// 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");
        }
    }
}
 
 

Output:

Converted long integer value to -128

References:

  • https://docs.microsoft.com/en-us/dotnet/api/system.sbyte.maxvalue?view=netframework-4.7.2
  • https://docs.microsoft.com/en-us/dotnet/api/system.sbyte.minvalue?view=netframework-4.7.2


Next Article
sbyte Keyword in C#

K

Kirti_Mangal
Improve
Article Tags :
  • C#
  • CSharp-SByte-Struct

Similar Reads

  • C# | Structures | Set - 1
    Structure is a value type and a collection of variables of different data types under a single unit. It is almost similar to a class because both are user-defined data types and both hold a bunch of different data types. C# provide the ability to use pre-defined data types. However, sometimes the us
    4 min read
  • sbyte Keyword in C#
    Keywords are the words in a language that are used for some internal process or represent some predefined actions. SByte is a keyword that is used to declare a variable that can store a signed value between the range of -128 to +127. It is an alias of System.SByte. SByte keyword occupies 1 byte (8 b
    2 min read
  • C# Program to Implement an Interface in a Structure
    Structure is a value type and a collection of variables of different data types under a single unit. It is almost similar to a class because both are user-defined data types and both hold a bunch of different data types. We can create a structure by using struct keyword. A structure can also hold co
    2 min read
  • Difference between byte and sbyte in C#
    In C#, a single byte is used to store 8-bits value. The byte and sbyte both are used for byte type of data. byte : This Struct is used to represent 8-bit unsigned integers. The byte is an immutable value type and the range of Byte is from 0 to 255. Example : C/C++ Code // C# program to demonstrate /
    2 min read
  • C# Program to Demonstrate the Static Constructor in Structure
    A Structure is a well-defined data structure that can hold elements of multiple data types. It is similar to a class because both are user-defined data types and both contain a bunch of different data types. You can also use pre-defined data types. However, sometimes the user might be in need to def
    2 min read
  • C# Arrays
    An array is a group of like-typed variables that are referred to by a common name. And each data item is called an element of the array. The data types of the elements may be any valid data type like char, int, float, etc. and the elements are stored in a contiguous location. Length of the array spe
    8 min read
  • Structures in C++
    C++ Structures are user defined data types which are used to store group of items of different data types. A structure creates a data type that can be used to group items of possibly different types into a single type. SyntaxBefore using structure, we have to first define the structure. The struct k
    9 min read
  • Array of Structures in C
    An array of structures is simply an array where each element is a structure. It allows you to store several structures of the same type in a single array. Let's take a look at an example: [GFGTABS] C #include <stdio.h> #include <string.h> // Structure definition struct A { int var; }; in
    6 min read
  • How to Pack a Struct in C?
    In C, when you declare a structure, the compiler allocates memory for its members, and the way it does this can involve adding padding between members for alignment purposes. struct packing refers to the arrangement of the members of a structure in memory so that there is no extra space left. In thi
    1 min read
  • strncpy() Function in C
    The strncpy() function in C is a predefined function in the string.h library used to copy a specified number of characters from one string to another. To use this function, we must include the <string.h> header file in our program. It copies up to n characters from the source string to the des
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences