خوش آموز درخت تو گر بار دانش بگیرد، به زیر آوری چرخ نیلوفری را
نوع داده Byte در ویژوال بیسیک دات نت
نوع داده Byte در ویژوال بیسیک می تواند مقادیر عددی بین 0 تا 255 را در خود نگهدارد. اندازه نوع داده Byte برابر با 8 بیت (1 بایت) می باشد.
برای نگهداری داده های باینری (binary) از نوع داده Byte استفاده کنید.
مقدار پیش فرض نوع داده Byte برابر با 0 می باشد.
در مثال زیر متغیر b از نوع Byte می باشد.
متن زیر قابل کپی کردن می باشد.
توضیحات نوع داده Byte
برای نگهداری داده های باینری (binary) از نوع داده Byte استفاده کنید.
مقدار پیش فرض نوع داده Byte برابر با 0 می باشد.
نکات برنامه نویسی مرتبط با نوع داده Byte
-
نوع داده Byte نمی تواند اعداد منفی را در خودش نگهدارد.
-
نوع داده متناظر با Byte در دات نت فریم ورک برابر با ساختار System.Byte می باشد.
-
برای ذخیره کردن داده های باینری از نوع داده String استفاده نکنید و الزاما از Byte استفاده کنید، اگر از String استفاده کنید محتویات باینری در هنگام تبدیل بین فرمتهای ANSI و Unicode از بین می روند و خراب می شوند.
مثال از نحوه استفاده از نوع داده Byte
در مثال زیر متغیر b از نوع Byte می باشد.
متن زیر قابل کپی کردن می باشد.
' The valid range of a Byte variable is 0 through 255.
Dim b As Byte
b = 30
' The following statement causes an error because the value is too large.
'b = 256
' The following statement causes an error because the value is negative.
'b = -5
' The following statement sets b to 6.
b = CByte(5.7)
' The following statements apply bit-shift operators to b.
' The initial value of b is 6.
Console.WriteLine(b)
' Bit shift to the right divides the number in half. In this
' example, binary 110 becomes 11.
b >>= 1
' The following statement displays 3.
Console.WriteLine(b)
' Now shift back to the original position, and then one more bit
' to the left. Each shift to the left doubles the value. In this
' example, binary 11 becomes 1100.
b <<= 2
' The following statement displays 12.
Console.WriteLine(b)
Dim b As Byte
b = 30
' The following statement causes an error because the value is too large.
'b = 256
' The following statement causes an error because the value is negative.
'b = -5
' The following statement sets b to 6.
b = CByte(5.7)
' The following statements apply bit-shift operators to b.
' The initial value of b is 6.
Console.WriteLine(b)
' Bit shift to the right divides the number in half. In this
' example, binary 110 becomes 11.
b >>= 1
' The following statement displays 3.
Console.WriteLine(b)
' Now shift back to the original position, and then one more bit
' to the left. Each shift to the left doubles the value. In this
' example, binary 11 becomes 1100.
b <<= 2
' The following statement displays 12.
Console.WriteLine(b)
نمایش دیدگاه ها (0 دیدگاه)
دیدگاه خود را ثبت کنید: