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 8529911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:08:14+00:00 2026-06-11T09:08:14+00:00

I am creating my first website in C#. I noticed I was getting some

  • 0

I am creating my first website in C#.

I noticed I was getting some duplication of extension methods in intellisense. Onfurther investigation it was these two:

public static void ThrowNullOrEmpty<T>(this IEnumerable<T> obj, string param)
{
}

public static void ThrowNullOrEmpty(this string obj, string param)
{
}

It seems string can also be IEnumerable<char>.

From a basis of compiling I can remove the string variant, but are there any performance issues or anything else I should be aware of?

UPDATE

Just tested over 1m iterations.

public bool IsNullOrEmpty1(string @this)
{
    return String.IsNullOrEmpty(@this);
}

vs

public bool IsNullOrEmpty2<T>(IEnumerable<T> @this)
{
    return @this == null || !@this.Any();
}

IsNullOrEmpty1 clocked 12 ms on my development machine, IsNullOrEmpty2 (125 – 250ms), so 10 – 20 times slower.

In the real world, I took an extremely high figure of 30m iterations per month, which translates back to 1388 per minute (12 hour day). The result was less than 1ms for both.

So, removing IsNullOrEmpty1 is not the best approach but its not a site killer either.

  • 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-06-11T09:08:15+00:00Added an answer on June 11, 2026 at 9:08 am

    It probably depends on the implementation of those methods – the string version could be optimized for performance, while the IEnumerable<T> one needs to be more general. Calling a generic method has no overhead, it is already resolved to the correct generic parameter at compile time.

    The string version can be implemented like this, which has very little overhead (it basically needs to make two comparisons):

    if (String.IsNullOrEmpty(value))  
    

    The IEnumerable<T> on the other hand probably has to be implemented something like:

    if (value == null || !value.Any())
    

    The key here is the Any call which will invoke the GetEnumerator method and return an enumerator. (For simplicity, we will overlook the performance optimizations that the framework might use internally for some types, here). This means that the implementation actually creates a new object, which will later need to be garbage collected – both will require more clock cycles than making the two comparisons mentioned in the string version.

    In practice, unless these methods are called very frequently, I doubt there is any significant performance difference.

    Btw, the reason why this works, is that string is an IEnumerable<char>.

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

Sidebar

Related Questions

Ok so I'm nearly done creating my first website. However it doesn't seem to
I'm following the video on the Sencha website, for creating my first application. This
So I am creating my own website for the first time and after a
Hey this is my first question on this website. Im creating a webpage for
I've just started creating my first MVC website; what's the best practice to prevent
I am creating a .NET website, and this is my first time using a
I am creating a responsive website, and have just noticed a strange behaviour in
I am creating a website using Python and the Bottle framework for the first
I am creating my first website that I am taking live soon. It is
I'm trying out my first website in rails and i'm trying to creating 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.