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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:18:35+00:00 2026-05-11T09:18:35+00:00

I have a method that accepts a bunch of strings in seperate parameters public

  • 0

I have a method that accepts a bunch of strings in seperate parameters

public string GetQueryString(string string1, string string2, string string3...) 

It should return a string in the form of

'string1:value1 string2:value2 string3:value3...' 

Because I don’t want to put reflection logic in the callers of GetQueryString, I think working with string[,] parameters is not an option.

What I need now is a way to walk through all my parameters and add ‘parName:parValue‘ to my StringBuilder.
Currently I do this by checking each of them with an if clause

if (!string.IsNullOrEmpty(string1))     sb.AppendFormat('{0}:{1}', 'string1', string1); 

How can this be improved?

–CLARIFICATION–
What I believe the OP wants to do is something like this:

string str1 = 'Hello'; string s2 = 'World'; string MyStr = 'Greetings'; string YourStr = 'Earthlings'; string query = GetQueryString(str1, s2, MyStr, YourStr); 

and have it return 'str1:Hello s2:World MyStr:Greetings YourStr:Earthlings'

–EDIT–
clarification is correct.
Furthermore, because my method is called GetQueryString doesn’t mean I’m working on an HTML query string.. In this particular case it is actually a Lucene query string. But it could be any search function that can parse strings to a query..

  • 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. 2026-05-11T09:18:36+00:00Added an answer on May 11, 2026 at 9:18 am

    The problem is, as soon as you compile this, the variable names will go away. Reflection won’t even help you.

    The only thing I can think of that may work, is to use a expression tree (.NET v3.5+)

     string GetQueryString(Expression<Func<String, string>> exprTree )  {       // walk expreTree.        // exprTree.Body.Left.Name would be the name of the variable      // exprTree.Body.Left.Value would be it value.  }   string q = GetQueryString((str1, s2, MyS, YourS) => str1 + s2 + MyS + YourS); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that has 2 output parameters. The method should take an
I have a custom method that accepts two parameters. I am using this method
I have a method that accepts a String argument. The String could contain an
I have a Java method that accepts a Long value: (in Java) public void
I have a method that accepts a generic delegate as a parameter, and inserts
I have a method that accepts an IEnumerable-decimals and performance various math functions. I
I have a method that accepts a sender and is called with a UIbutton.
I have a method Foo4 that accepts a parameter of the type Func<>. If
I have a method that prints private variable of the class. public class Test
I have a method that accepts three NSMutableArrays, one as Input and two as

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.