Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6372551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:15:14+00:00 2026-05-25T01:15:14+00:00

The program does similar things again and again. I want to reduce the code

  • 0

The program does similar things again and again. I want to reduce the code I use.
It’s an example, in this example it is not needed but I will do another thing similar in the future. Now I’m confused and said “Why should I copy the same codes one by one?”

But I get ‘Object’ does not contain a definition for ‘ComputeHash’ error. In runtime they won’t be objects, they are classes. So they don’t have the same variable type. What should I do?

private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog op = new OpenFileDialog();
    op.Filter = "ALL files(*.*)|*.*";
    if (op.ShowDialog() == DialogResult.OK)
    {
        textBox1.Text = String.Empty;
        var list = new ArrayList() { crc32, md5, sha1 };
        foreach (var checksum in list)
        {
            using (FileStream fs = File.Open(op.FileName, FileMode.Open))
            {
                foreach (byte b in checksum.ComputeHash(fs))
                {
                    hash += b.ToString("x2").ToLower();
                }
                textBox1.Text += hash + "\r\n";
                hash = String.Empty;
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:15:14+00:00Added an answer on May 25, 2026 at 1:15 am

    It’s because you’re using the non-generic ArrayList type. If you change it to:

    var list = new List<HashAlgorithm> { crc32, md5, sha1, ... };
    

    it’ll be fine. Basically, the compile-time type of checksum is currently object, not HashAlgorithm.

    You should use strongly typed collections whenever you can.

    (You should also use using statements for streams – currently you’re not closing the stream.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason the following doesn't crash like my program does, but I'm pretty
I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first,
I have a program which does a system call: latex somefile.latex This runs ok,
How does this program access other processes memory? How can it write into the
I did find other posts similar to this, but wanted a little extra information
My program does some network activity in a background thread. Before starting, it pops
In a nutshell what my program does is: it executes and takes user input
I have a program that does recursive calls for 2 billion times and the
I am writing a program that does a lot of writes to a Postgres
I'm looking for an elegant Python program that does a BFS traveral of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.