很简单的问题让我发疯 [英] Very simple problem drives me crazy

查看:64
本文介绍了很简单的问题让我发疯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有这段代码:



Hi,

I have this code:

private void btn_Click(object sender, EventArgs e)
{
    byte[] data = File.ReadAllBytes("a.txt");

    int[] totals = new int[256];

    foreach (byte in data)
    {
        ++totals[b];
    }
}





输出为:http://i45.tinypic.com/2nquqhi.png [ ^ ]



但是如何显示a.txt中每个字符的频率(出现次数)还有?

并存储在:long [] freqar = new long [256];



The output is this: http://i45.tinypic.com/2nquqhi.png[^]

But how can i show the frequency(occurrence) of each character in a.txt also?
and store it in: long[] freqar=new long[256];

推荐答案

不!这样做:

No! Do this:
foreach(byte value in data)
    ++totals[value];



你现在能看到你的错误吗?现在你有了事件。希望你能继续自己计算频率。



-SA


这篇关于很简单的问题让我发疯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆