将arraylist对象转换为byte []

问题描述:

我有一个名为list的araylist对象,在这里我想将arraylist对象转换为byte [],同时进行以下编码,并给出一个错误:源数组中的至少一个元素无法转换为目标对象arraytype
我的编码:

I have araylist object named list, here i want to convert my arraylist object to byte[], while doing the below coding its giving an error: "At least one element in the source array could not be cast down to the destination arraytype" my coding:

 byte[] obj= new byte[list.Count];
     list.CopyTo(obj); 

这里我的数组列表对象从ssrs报表返回报表数据。我想在这里做什么来解决这个问题

here my array list objects returns report data from ssrs reports.what i want to do here to solve this issue.

看看这个(这将向您显示可能存在问题的地方)

Look at this (this will show you where can be a problem)

        List<object> list = new List<object>();
        list.Add((byte)1);
        list.Add((byte)0);
        list.Add("wtf");
        list.Add((byte)1);
        byte[] obj = list.OfType<byte>().ToArray();
        if(obj.Length!=list.Count)
        {
            //Exception, not all objects in list is 'byte'
        }