C# 中的位元組結構

WBOY
發布: 2023-09-04 10:25:10
轉載
1085 人瀏覽過

C# 中的字节结构

Byte Struct在C#中表示一個8位元無符號整數。以下是欄位:

##12
序號 欄位和描述
MaxValue表示Byte的最大可能值。這個字段是常數。

MinValue表示Byte的最小可能值 field is constant.

Following are some of the methods −

#Sr.no Field & Description#12Equals(Byte)Equals(Object)GetHashCode()
CompareTo(Byte)

## Compares this instance to a specified 8-bit unsigned integer and returns an indication of their relative values.

#CompareTo(Object) ##將此實例與指定物件進行比較,並 returns an indication of their relative values.

#3

Returns a value indicating whether this instance and a 指定的Byte物件表示相同的值。

4

傳回一個值,指示此實例是否 等於指定的對象。

5

傳回此實例的雜湊碼。

6

GetTypeCode().

傳回值型別 Byte 的 TypeCode。

######範例###### 示範###
using System;
public class Demo {
   public static void Main() {
      string str = "186";
      try {
         byte val = Byte.Parse(str);
         Console.WriteLine(val);
      }
      catch (OverflowException) {
         Console.WriteLine("Out of range of a byte.", str);
      }
      catch (FormatException) {
         Console.WriteLine("Out of range of a byte.", str);
      }

   }
}
登入後複製
###輸出######這將產生以下輸出−# ##
186
登入後複製
###Example######讓我們來看另一個範例−###### 即時示範###
using System;
public class Demo {
   public static void Main() {
      byte[] arr = { 0, 10, 50, 90, 100, 150 };
      foreach (byte b in arr) {
         Console.Write(" ", b.ToString());
         Console.Write(b.ToString("D4") + " ");
         Console.WriteLine(b.ToString("X4"));
      }
   }
}
登入後複製
###輸出######這將產生以下輸出−# ##
 0000   0000
 0010   000A
 0050   0032
 0090   005A
 0100   0064
 0150   0096
登入後複製
###

以上是C# 中的位元組結構的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!