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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:42:08+00:00 2026-05-25T12:42:08+00:00

As is described at Microsoft Site ,String.Format arranges some String Variables into a single

  • 0

As is described at Microsoft Site ,String.Format arranges some String Variables into a single String and is another way how to concate string’s in c#.

string.Format("Name = {0} Surname = {1}",name,surname);

My question is how does this work ?
Is this method a Special method ,and can i create a method similar to this one which accepts at every {n} only an Integer .
Or is this method interpreted in a different way by compiler ,if yes than how does the compiler accesses this method .

If it’s possible i would like to see ,how does the compiler interpret this Method.

PS : How does it work ,when you can send as much parameters as you want to a method ?

[EDIT]
Does it mean ,that String.Format takes the first Parameter and filter’s into with a Regex or Whatever tool (Split etc) to get where {Number} is and places there a String token from second params portion ?

  • 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-25T12:42:09+00:00Added an answer on May 25, 2026 at 12:42 pm

    Sending a variable number of parameters to a method is done like this:

    public static string MyStringFormat(string formatString, params object [] args)
    {
    
    }
    

    You can now pass as many parameters as you like to this:

    MyStringFormat("{0}{1}",42,"Hello World")
    MyStringFormat("{0}{1}{2}",42,"Hello World",999.9)
    

    Within the method, these arguments are simply an array (of object in this case).
    here are the docs on the params keyword.

    As for writing you own method to accept numeric input like Format does, this would be one way (using regular expressions):

     public static string MyStringFormat(string formatString, params object[] args)
        {
            var regex = new Regex("{([0-9]*)}");
            return regex.Replace(formatString,m =>
                               {
                                   int index = int.Parse(m.Groups[1].Value);
                                   if(index<args.Length)
                                      return args[index].ToString();
                                   return String.Empty;
                               });
        }
    

    Live example: http://rextester.com/rundotnet?code=OMZC13551

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

Sidebar

Related Questions

Like described in the title, is there some library in the Microsoft framework which
I'm having the problem described here: http://groups.google.com/group/microsoft.public.xml.soap/browse_thread/thread/029ee5b5d4fa2440/0895d73c5c3720a1 I am consuming a Web Service using
I'm trying to register an atl service using ExeName.exe /service as described here: http://msdn.microsoft.com/en-us/library/74y2334x(VS.80).aspx
As described in another question , I have a set of Model objects and
How can polymorphism be described in an easy-to-understand way? We can find a lot
I'm confusing myself reading Microsoft's documentation on the Lazy<T>(bool) constructor. The parameter is described
A proper header format in python is described here . Using either VIM or
Is there a way to use the naming convention described in the title to
I'm using the Microsoft.Jet.OLEDB.4.0 provider for a basic connection in some VBA code, and
Problem is described and demonstrated on the following links: Paul Stovell WPF: Blurry Text

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.