日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > C# >内容正文

C#

c#中的long类型示例_C#中带示例的带符号字节数组

發(fā)布時(shí)間:2025/3/11 C# 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c#中的long类型示例_C#中带示例的带符号字节数组 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

c#中的long類型示例

C#中的有符號(hào)字節(jié)數(shù)組 (Signed Byte Array in C#)

In C#.Net, we can create a signed byte array by using sbyte, sbyte is used to store both of the values (negative and positive) between the range of -128 to 127 (Signed 8 bits integer).

在C#.Net中,我們可以使用sbyte創(chuàng)建一個(gè)帶符號(hào)的字節(jié)數(shù)組, sbyte用于存儲(chǔ)-128到127 (帶符號(hào)的8位整數(shù))范圍內(nèi)的兩個(gè)值(負(fù)值和正值)。

It occupies 1-byte memory for each element, if array size is 10, it will take 10 bytes memory.

每個(gè)元素占用1字節(jié)的內(nèi)存 ,如果數(shù)組大小為10,則將占用10字節(jié)的內(nèi)存。

聲明一個(gè)有符號(hào)的字節(jié)[] (Declaration of a signed byte[])

1) Array declaration with initialization

1)初始化數(shù)組聲明

Syntax: sbyte[] array_name = { byte1, byte2, byte2, ...};Example: sbyte[] arr1 = { -128, -100, 0, 100, 127};

Array decoration with fixed number of elements

具有固定數(shù)量元素的陣列裝飾

Syntax: sbyte[] array_name = new sbyte[value];Example: sbyte[] arr2 = new sbyte[5];

3) Array declaration with user input

3)帶有用戶輸入的數(shù)組聲明

Syntax: sbyte[] array_name = new sbyte[variable];Example: sbyte[] arr3 = new sbyte[n];

訪問(wèn)帶符號(hào)字節(jié)數(shù)組的元素 (Accessing signed byte array's elements)

Like other types of arrays – we can access the array elements with its index, index starts with 0 and ends with n-1. Here, n is the total number of array elements.

像其他類型的數(shù)組一樣,我們可以使用其索引訪問(wèn)數(shù)組元素,索引以0開頭,以n-1結(jié)尾。 此處, n是數(shù)組元素的總數(shù)。

Example:

例:

Consider the given example – Here, we are declaring 3 arrays with 3 different approaches, initializing the arrays either with default values or user input. To print the array elements, we are using foreach loop, we can also use for or while loop with loop counter to access the array elements.

考慮給定的示例–在這里,我們使用3種不同的方法聲明3個(gè)數(shù)組,并使用默認(rèn)值或用戶輸入來(lái)初始化數(shù)組。 為了打印數(shù)組元素,我們使用了foreach loop ,我們也可以使用帶有循環(huán)計(jì)數(shù)器的for或while循環(huán)來(lái)訪問(wèn)數(shù)組元素。

using System; using System.Text;namespace Test {class Program{static void Main(string[] args){//declaring signed byte[] & initializing it with 5 elementssbyte[] arr1 = { -128, -100, 0, 100, 127 };//printing all bytes of arr1Console.WriteLine("arr1 items...");foreach (sbyte item in arr1){Console.WriteLine(item);}Console.WriteLine(); //to print a line //declaring array for 5 elements //reading values and assigning to array sbyte[] arr2 = new sbyte[5];//reading values from the userfor (int loop = 0; loop < 5; loop++){Console.Write("Enter a byte (b/w -128 to 127): ");arr2[loop] = sbyte.Parse(Console.ReadLine());}//printing all bytes of arr2Console.WriteLine("arr2 items...");foreach (sbyte item in arr2){Console.WriteLine(item);}Console.WriteLine(); //to print a line //read value of "n" and declare array for "n" elements//reading values and assigning to array Console.Write("Enter length of the array: ");int n = int.Parse(Console.ReadLine());//declaring array for n elementssbyte[] arr3 = new sbyte[n];//reading values from the userfor (int loop = 0; loop < n; loop++){Console.Write("Enter a byte (b/w -128 to 127): ");arr3[loop] = sbyte.Parse(Console.ReadLine());}//printing all bytes of arr3Console.WriteLine("arr3 items...");foreach (sbyte item in arr3){Console.WriteLine(item);}//hit ENTER to exitConsole.ReadLine();}} }

Output

輸出量

arr1 items... -128 -100 0 100 127Enter a byte (b/w -128 to 127): 127 Enter a byte (b/w -128 to 127): 100 Enter a byte (b/w -128 to 127): -100 Enter a byte (b/w -128 to 127): 0 Enter a byte (b/w -128 to 127): 20 arr2 items... 127 100 -100 0 20Enter length of the array: 3 Enter a byte (b/w -128 to 127): -128 Enter a byte (b/w -128 to 127): 0 Enter a byte (b/w -128 to 127): 127 arr3 items... -128 0 127

翻譯自: https://www.includehelp.com/dot-net/signed-byte-array-with-example-in-c-sharp.aspx

c#中的long類型示例

總結(jié)

以上是生活随笔為你收集整理的c#中的long类型示例_C#中带示例的带符号字节数组的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。