c#将字节数组转换成整数_将整数数组转换为C#中的列表

c#将字节数组转换成整数

Given an integer array and we have to convert it into a list in C#.

给定一个整数数组,我们必须将其转换为C#列表。

将int []转换为List <int> (Converting int[] to List<int>)

A list is used to represent the list of the objects, it is represented as List<T>, where T is the type of the list objects/elements.

列表用于表示对象的列表,它表示为List <T> ,其中T是列表对象/元素的类型。

A list is a class which comes under System.Collections.Generic package, so we have to include it first.

列表是System.Collections.Generic包下的一个类,因此我们必须首先包含它。

To convert an integer array to the list, we use toList() method of System.Linq. Here, is the syntax of the expression that converts an integer array to the list.

要将整数数组转换为列表 ,我们使用System.Linq的 toList()方法。 这是将整数数组转换为列表的表达式的语法。

    List<T> arr_list = array_name.OfType<T>().ToList();

Here, T is the type and array_name is the input array.

在这里, T是类型, array_name是输入数组。

Example (for integer array)

示例(对于整数数组)

    List<int> arr_list = arr.OfType<int>().ToList();

Here, arr is the input array.

在这里, arr是输入数组。

Syntax:

句法:

    var array_name = new[] {initialize_list/elements};

C#程序将整数数组转换为列表 (C# program to convert an integer array to the list )

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;


namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = new[] { 10, 20, 30, 40, 50 };

            //creating list 
            List<int> arr_list = arr.OfType<int>().ToList();

            //printing the types of variables
            Console.WriteLine("type of arr: " + arr.GetType());
            Console.WriteLine("type of arr_list: " + arr_list.GetType());

            Console.WriteLine("List elements...");
            //printing list elements 
            foreach (int item in arr_list)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();


            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

输出量

type of arr: System.Int32[]
type of arr_list: System.Collections.Generic.List`1[System.Int32]
List elements...
10 20 30 40 50


翻译自: https://www.includehelp.com/dot-net/convert-an-integer-array-to-the-list-in-c-sharp.aspx

c#将字节数组转换成整数

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值