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

  • Home
  • SEARCH
  • 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 6651849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:03:37+00:00 2026-05-26T01:03:37+00:00

For example this encryption function could be called a Utility ? public static string

  • 0

For example this encryption function could be called a Utility ?

public static string HashText(string text)
{
    byte[] encodedBytes;
    using (var md5 = new MD5CryptoServiceProvider())
    {
        var originalBytes = Encoding.UTF8.GetBytes(text);
        encodedBytes = md5.ComputeHash(originalBytes);
    }
    return Encode(encodedBytes);
}

While this other function would be a Helper ?

public static string Encode(byte[] byteArray)
{
    if (byteArray == null || byteArray.Length == 0)
        return "";

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < byteArray.Length; i++)
    {
        sb.Append(byteArray[i].ToString("x2"));
    }
    return sb.ToString();
}

How about a Extension could you provide any simple examples of when I should turn something into a extension of a method ?

  • 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-26T01:03:38+00:00Added an answer on May 26, 2026 at 1:03 am

    When to make a method a static helper method or an extension method is a subjective decision. If you need help deciding whether or not to make a method an extension method, then ask yourself whether it makes sense to include that method in the other class as a normal instance method.

    For example, you might have a method like this:

    public class Customers
    {
        public static Customer GetCustomer(string name)
        {
            // implementation
            return customer;
        }
    }
    

    Does this make sense as an instance method of the String class?

    public class String
    {
        public Customer GetCustomer()
        {
            // implementation
            return customer;
        }
    
        // other methods
    }
    

    Design-wise this polutes the String class with a completely unrelated class. It makes the String class a “kitchen sink” that collects anything and everything remotely related to strings.

    On the other hand, suppose you have method like this:

    public class StringHelper
    {
        public static string[] Split(string s, string separator)
        {
                // implementation
                return array;
        }
    }
    

    Does this make sense as an instance method of the String class?

    public class String
    {
        public string[] Split(string separator)
        {
                // implementation
                return array;
        }
    
        // other methods
    }
    

    Absolutely! This an natural extension to the existing Split functionality. It could have been included in the original implementation of String.

    Everything in between can be judged on a case-by-case basis.

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

Sidebar

Related Questions

Example: /** * This function will determine whether or not one string starts with
for example this code var html = <p>This text is <a href=#> good</a></p>; var
For example this article introduces them. What is the benefit? Static analysis seems cool
I use this code to encrypt a string (basically, this is the example given
I am using Botan utility to perform encryption. When I initialize my connection to
I'm trying to adapt this DES encrypting example to AES, so I made the
For example: This is main body of my content. I have a footnote link
How to get a file's creation date or file size, for example this Hello.jpg
Trying to extract strings that are wrapped in double brackets. For example [[this is
How i can get full right name of generic type? For example: This code

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.