C#中的字节结构及其方法
byte是.NET框架类库的预定义结构。我们知道,.NET框架中的每个结构都包含一些对其进行操作的方法和属性。
字节结构有以下重要方法:
byte.Equals()
byte.Parse()
byte.MaxValue
byte.MinValue
1)个字节
此方法用于检查两个给定的字节对象是否相等。它返回布尔结果。
2)byte.Parse()
此方法用于将字符串转换或解析为字节。
3)byte.MaxValue
这是字节结构的get属性。它返回字节变量的最大可能值。
4)byte.MinValue
这是字节结构的get属性。它返回字节变量的最大可能值。
以上所有方法都可以借助程序轻松理解:
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);
}
}
}上面的程序产生以下结果:
输出结果
Value is : 125 Both are not equal MaxValue of byte : 255 MinValue of byte : 0