Home » .Net

byte structure and its methods in C#

Learn: byte structure and its methods in C#.Net, it’s a predefined structure of .Net framework; here we are going to discuss its methods and properties with example.

byte is a pre-define structure of .NET framework class library. And as we know that every structure in .NET framework contains some methods and properties to operate on it.

There are following important methods of byte structure:

  1. byte.Equals()
  2. byte.Parse()
  3. byte.MaxValue
  4. byte.MinValue

1) byte.Equals

This method is used to check two given byte object are equal or not. It returns boolean result.

2) byte.Parse()

This method is used to convert or parse string to byte.

3) byte.MaxValue

This is a get property of byte structure. It returns maximum possible value of byte variable.

4) byte.MinValue

This is a get property of byte structure. It returns maximum possible value of byte variable.

All above method can easily understand with the help of program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            bool flag = false;
            byte val;

            val = byte.Parse("125");

            Console.WriteLine("Value is : "+val);

            flag = byte.Equals(123,125);

            if(flag == true)
                Console.WriteLine("Both are equal");
            else
                Console.WriteLine("Both are not equal");

            Console.WriteLine("MaxValue of byte : " + byte.MaxValue);
            Console.WriteLine("MinValue of byte : " + byte.MinValue);
        }
    }
}

Above program produce following result:

Output

Value is : 125
Both are not equal
MaxValue of byte : 255
MinValue of byte : 0


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.