简体   繁体   English

HashSet和字节数组-不知道如何从该HashSet获取数据

[英]HashSet and byte array-don't know how to get the data from that HashSet

I am trying to read that HashSet but I get only "System.Byte[]" as the output... 我正在尝试阅读该HashSet,但我仅获得“ System.Byte []”作为输出...

HashSet<byte[]> array2 = hash1Copy;


            foreach (var bullet in array2.OfType<byte[]>())
            {
                textBoxResults.Text += bullet + "\n"; 
            }

I know thats a beginner question, but I need your help... 我知道这是一个初学者的问题,但是我需要您的帮助...

There are a few issues I think, one is of naming, you have something named array2, but it is not an array, it is a HashSet that contains a number of arrays. 我认为有几个问题,一个是命名问题,您有一个名为array2的东西,但它不是数组,它是一个HashSet,其中包含许多数组。 Naming it array2 may have confused you in thinking that what is returned is a single byte. 将其命名为array2可能会使您感到困惑,认为返回的是单个字节。

Because you have a HashSet of byte arrays your foreach gives you a single byte array in bullet each time it loops. 因为您有一个HashSet字节数组,所以每次循环时,foreach都会在子弹中为您提供单个字节数组。 A byte array doesn't cast to a useful string by default, you would have to make a string of it using System.Text.Encoding.whateverencoding.GetString. 默认情况下,字节数组不会转换为有用的字符串,您必须使用System.Text.Encoding.whateverencoding.GetString对其进行字符串处理。

If you wanted to print each single byte you need another foreach inside your current foreach. 如果要打印每个单个字节,则在当前的foreach中需要另一个foreach。

How can I print all duplicated entries ? 如何打印所有重复的条目?

                int countForeach = 1;
            foreach (var bullet in arrayContainsHashes.OfType<byte[]>())
            {
                textBoxResults.Text += countForeach + ".:";
                foreach (var item in bullet)
                {
                    textBoxResults.Text += item.ToString();

                }
                countForeach++;
                textBoxResults.Text += "\n";
            }

Now, it guves me every hash 现在,它骗了我每一个哈希

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM