c#中的long类型示例

C#中的无符号字节数组 (Unsigned Byte Array in C#)

In C#.Net, we can create an unsigned byte array by using byte, byte is used to store only positive values between the range of 0 to 255 (Unsigned 8 bits integer).

在C#.Net中,我们可以使用byte创建一个无符号的字节数组, byte用于仅存储0到255 (无符号的8位整数)范围内的正值。

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

每个元素占用1字节的内存 ,如果数组大小为10,则将占用10字节的内存。

声明无符号字节[] (Declaration of a unsigned byte[])

1) Array declaration with initialization

1)初始化数组声明

    Syntax:   byte[] array_name = { byte1, byte2, byte2, ...};
Example:    byte[] arr1 = { 0, 100, 120, 210, 255};

Array decoration with fixed number of elements

具有固定数量元素的阵列装饰

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

3) Array declaration with user input

3)带有用户输入的数组声明

    Syntax: byte[] array_name = new byte[variable];
Example:    byte[] arr2 = new byte[n];

访问无符号字节数组的元素 (Accessing unsigned 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.

像其他类型的数组一样,我们可以使用其索引访问数组元素,索引以0开头,以n-1结尾。 此处, n是数组元素的总数。

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个数组,并使用默认值或用户输入来初始化数组。 为了打印数组元素,我们使用了foreach loop ,我们也可以使用带有循环计数器的for或while循环来访问数组元素。

using System;
using System.Text;
namespace Test
{class Program
{static void Main(string[] args)
{//declaring unsigned byte[] & initializing it with 5 elements
byte[] arr1 = { 0, 100, 120, 210, 255};
//printing all bytes of arr1
Console.WriteLine("arr1 items...");
foreach (byte item in arr1)
{Console.WriteLine(item);
}
Console.WriteLine(); //to print a line
//declaring array for 5 elements
//reading values and assigning to array
byte[] arr2 = new byte[5];
//reading values from the user
for (int loop = 0; loop < 5; loop++)
{Console.Write("Enter a byte (b/w -128 to 127): ");
arr2[loop] = byte.Parse(Console.ReadLine());
}
//printing all bytes of arr2
Console.WriteLine("arr2 items...");
foreach (byte 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 elements
byte[] arr3 = new byte[n];
//reading values from the user
for (int loop = 0; loop < n; loop++)
{Console.Write("Enter a byte (b/w -128 to 127): ");
arr3[loop] = byte.Parse(Console.ReadLine());
}
//printing all bytes of arr3
Console.WriteLine("arr3 items...");
foreach (byte item in arr3)
{Console.WriteLine(item);
}
//hit ENTER to exit
Console.ReadLine();
}
}
}

Output

输出量

arr1 items...
0
100
120
210
255
Enter a byte (b/w -128 to 127): 0
Enter a byte (b/w -128 to 127): 100
Enter a byte (b/w -128 to 127): 150
Enter a byte (b/w -128 to 127): 200
Enter a byte (b/w -128 to 127): 255
arr2 items...
0
100
150
200
255
Enter length of the array: 3
Enter a byte (b/w -128 to 127): 0
Enter a byte (b/w -128 to 127): 225
Enter a byte (b/w -128 to 127): 255
arr3 items...
0
225
255

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

c#中的long类型示例

c#中的long类型示例_C#中带示例的无符号字节数组相关推荐

  1. 汇编语言求无符号字数组中的最大偶数

    题目 编制一个汇编程序,求首地址为 ARRAY 的N 个非零无符号字数组中最大偶数,并把它存放在 AX 寄存器中.如果数组中无偶数,则 AX 中置 0. DATAS SEGMENTARRAY DW 1 ...

  2. 在 BUF 和 BUF+1、BUF+2 单元分别放有一个无符号字节型数,编程序将其 中最大数存入 MAX 单元,并在屏幕上显示。

    问题描述: 在 BUF 和 BUF+1.BUF+2 单元分别放有一个无符号字节型数,编程序将其 中最大数存入 MAX 单元,并在屏幕上显示. 汇编代码,已调试 DATA SEGMENTBUF DB 7 ...

  3. c++ cdi+示例_C ++中带有示例的本地类

    c++ cdi+示例 C ++中的本地类 (Local Class in C++) In C++, generally a class is declared outside of the main( ...

  4. c语言中浮点数和整数转换_C中的数据类型-整数,浮点数和空隙说明

    c语言中浮点数和整数转换 C中的数据类型 (Data Types in C) There are several different ways to store data in C, and they ...

  5. mysql数据库中常用的类型_MySQL数据库中常用字段类型

    MySQL数据库中常用字段类型 整数型:TINYINT,SMALLINT,INT,BIGINT 小数型:FLOAT,DOUBLE,DECIMAL(M,D) 字符型:CHAR,VARCHAR 日期型:D ...

  6. c语言中的无符号字节,C语言之有符号数和无符号数

    我们知道,在C语言中存在无符号数和有符号数(一些高级语言如Java里面是没有无符号数的),但是对于计算机而言,其本身并不区别有符号数和无符号数,因为在计算机里面都是0或者1,但是在我们的实际使用中有时 ...

  7. c 语言bool 类型数据_C ++中的bool数据类型

    c 语言bool 类型数据 In C++ programming language, to deal with the Boolean values – C++ added the feature o ...

  8. c# 小程序支付后台示例_C中的#if指令示例| C预处理程序

    c# 小程序支付后台示例 The #if is a preprocessor directive in C programming language and it is used for condit ...

  9. c语言 函数的参数传递示例_C ++中带有示例的nearint()函数

    c语言 函数的参数传递示例 C ++附近的int()函数 (C++ nearbyint() function) nearbyint() function is a library function o ...

最新文章

  1. visualvm远程监控jvm_8款JVM性能调优监控工具(提高开发效率)
  2. 12. final修饰符
  3. Python Django 可变参数*与**的区别
  4. 十九、面试必考,Java中的this关键字
  5. 在SAP CDS view上添加扩展字段后激活,背后的实现原理
  6. dotnet core TargetFramework 解析顺序探索
  7. 2017.12.26
  8. Java - 计算不同字符或数字的个数
  9. 【DSP开发】解读TI的KeyStone II云技术应用
  10. qlineedit限制输入数字_请注意:输入设计需要这些交互反馈
  11. matlab 线型、标记、颜色
  12. DirectX 9.0 (5) 点光源
  13. wps永久关闭热点功能
  14. 汇编指令学习(AND,OR,XOR,NOT)
  15. Alpha、Beta、RC、GA、LTS等软件各个版本号的含义
  16. mysql的字段空格是null_空字符与空格字符、NULL、空字符串
  17. 解决排列组合问题的通用算法
  18. jquery设置checkbox选中和未选中的方式
  19. android 下划线edittext,Android实现EditText添加下划线
  20. LTC逆袭活跃地址一周增长84! ETH、BTC、BCH每秒交易均呈负增长! 以太坊网络传播时间再缩短| 数据周榜...

热门文章

  1. java父类shape_为什么该父类无法调用其子类.__ShapeCircle_public_perimeter_getType_shapej__169IT.COM...
  2. LDAP----manage-account
  3. Docker入门-安装
  4. linux tips 技巧笔记二
  5. 自建CDN Xnign产品指标
  6. mysql悲观锁总结和实践
  7. 浮动元素的均匀分布和两端对齐
  8. bzoj 2121 DP
  9. 2012年3月编程语言排行榜:JavaScript超越Perl和Python
  10. 5.5的performance_schema