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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:47:53+00:00 2026-06-03T19:47:53+00:00

I have two extension methods: public static string ToString(this List<object> list, char delimiter) {

  • 0

I have two extension methods:

    public static string ToString(this List<object> list, char delimiter)
    {
        return ToString<object>(list, delimiter.ToString());
    }

    public static string ToString(this List<object> list, string delimiter)
    {
        return ToString<object>(list, delimiter);
    }

When I use this:

    char delimiter = ' ';
    return tokens.ToString(delimiter);

It won’t work. The char overload doesn’t show up in the code completion list either. Can anybody tell me how to make this work?

EDIT

I accidentally forgot to mention that there are in fact 3 extension methods, the third being:

    public static string ToString<T>(this List<T> list, string delimiter)
    {
        if (list.Count > 0)
        {
            string s = list[0].ToString();

            for (int i = 1; i < list.Count; i++)
                s += delimiter + list[i].ToString();

            return s;
        }

        return "";
    }
  • 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-03T19:47:55+00:00Added an answer on June 3, 2026 at 7:47 pm

    Add reference to the class in which you have the extension methods:

    using MyApplicationNamespace.ToStringExtensionClass;
    

    VS / ReSharper doesn’t offer to add reference automatically simply because the method is already recognized, just not with that particular signature.

    Also, your methods themselves don’t compile unless you have a third extension methods with generic parameter.

    The way they work for me (compile and logically):

    public static string ToString(this List<object> list, char delimiter)
    {
        return ToString(list, delimiter.ToString());
    }
    
    public static string ToString(this List<object> list, string delimiter)
    {
        return string.Join(delimiter, list);
    }
    

    Usage will then be:

    var list = new List<int> { 1, 2, 3, 4, 5 };
    var str = list.Cast<object>().ToList().ToString(' ');
    

    If you want to avoid casting and make the methods generic, change them to:

    public static string ToString<T>(this List<T> list, char delimiter)
    {
        return ToString(list, delimiter.ToString());
    }
    
    public static string ToString<T>(this List<T> list, string delimiter)
    {
        return string.Join(delimiter, list);
    }
    

    And then the usage is much cleaner:

    var list = new List<int> { 1, 2, 3, 4, 5 };
    var str = list.ToString(' ');
    

    EDIT

    So after your edit I understand your problem better.
    You should lose the non-generic methods and have generic overload to accept char as well.

    public static string ToString<T>(this List<T> list, char delimiter)
    {
        return ToString(list, delimiter.ToString());
    }
    
    public static string ToString<T>(this List<T> list, string delimiter)
    {
        ...
    }
    

    Also, the logic you are trying to implement can be easily achieved with:

    string.Join(delimiter, list);
    

    So you can basically delete all of those methods and just use that, unless you really want it as an extension method for lists.

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

Sidebar

Related Questions

This extension method does not work on two separate development machines: public static string
Consider two extension methods: public static T MyExtension<T>(this T o) where T:class public static
Say I have an overloaded extension method with the following two signatures: public static
I have an extension method with the following signature: public static Expression<Func<T, bool>> And<T>(this
I have to two extensions: public static IQueryable<T> Existing<T>(this IQueryable<T> qry) where T :
I have an extension method declared in this way: public static IEnumerable<TEntity> AsEnumerable<TEntity>(this IDBQueryable<TEntity>
When I have to write methods which return two values , I usually go
I have two extension methods that are very similar. I'd like to remove the
In C#, extension methods can be created by public static class MyExtensions { public
I have an extension method which takes in two list and compares them for

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.