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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:16:57+00:00 2026-06-06T23:16:57+00:00

Actually I can not even say exactly how that thing is called correctly but

  • 0

Actually I can not even say exactly how that thing is called correctly but I need something that can assign variables / properties / fields in one method. I will try to explain…
I have the following code:

txtBox.Text = SectionKeyName1; //this is string property of control or of any other type
if (!string.IsNullOrEmpty(SectionKeyName1))
{
    string translation = Translator.Translate(SectionKeyName1);
    if (!string.IsNullOrEmpty(translation))
    {
        txtBox.Text = translation;
    }
}

stringField = SectionKeyName2; //this is class scope string field
if (!string.IsNullOrEmpty(SectionKeyName2))
{
    string translation = Translator.Translate(SectionKeyName2);
    if (!string.IsNullOrEmpty(translation))
    {
        stringField = translation;
    }
}

stringVariable = SectionKeyName3; //this is method scope string variable
if (!string.IsNullOrEmpty(SectionKeyName3))
{
    string translation = Translator.Translate(SectionKeyName3);
    if (!string.IsNullOrEmpty(translation))
    {
        stringVariable = translation;
    }
}

As I see, this code can be refactored to one method, that receives the “object” to set and SectionKeyName. So it can be something like:

public void Translate(ref target, string SectionKeyName)
{
    target = SectionKeyName;
    if (!string.IsNullOrEmpty(SectionKeyName))
    {
        string translation = Translator.Translate(SectionKeyName);
        if (!string.IsNullOrEmpty(translation))
        {
            target = translation;
        }
    }
}

BUT: I will can not use that method in case when I want to assign texBox.Text, since properties can not be passed byref….
I found topic on SO where is solution for properties, but it solves the properties and I stuck with fields / variables….

Please help me to find the way to write a single method that will handle all of my cases…

//This method will work to by varFieldProp = Translate(SectionKeyName, SectionKeyName), but would like to see how to do it with Lambda Expressions.
public string Translate(string SectionKeyName, string DefaultValue)
{
    string res = DefaultValue; //this is string property of control or of any other type
    if (!string.IsNullOrEmpty(SectionKeyName))
    {
        string translation = Translator.Translate(SectionKeyName);
        if (!string.IsNullOrEmpty(translation))
        {
            res = translation;
        }
    }

    return res;
}

Thank you !!!

  • 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-06T23:16:59+00:00Added an answer on June 6, 2026 at 11:16 pm

    I think you want something like this:

    public void Translate(Action<string> assignToTarget, string SectionKeyName)
            {
                assignToTarget(SectionKeyName);
                if (!string.IsNullOrEmpty(SectionKeyName))
                {
                    string translation = Translator.Translate(SectionKeyName);
                    if (!string.IsNullOrEmpty(translation))
                    {
                        assignToTarget(translation);
                    }
                }
            }
    

    but it would be better if you simply remove the lambda and let the function returns the translated string to use when needed. Just for completeness, to call this function you can use:

    Translate(k=>textBox1.Text=k,sectionKeyName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im pretty confused about lambdas and actually im not even sure i need them
Been a loooooong time since I've actually coded straight c (not even C++ but
Actually Datalist not contain allowpaging property. so how can i set paging in datalist.
Actually I'm looking for a jQuery plug-in that can handle this: there is a
I was wondering how php files are actually secured. How come one can not
What I need is actually just a hint where I can start. I'm somewhat
Problem description is brief but I think I don't need to say much. When
I'm not sure exactly what went wrong here, but ReSharper 4.5 RTM seems to
Ive got some data (not that the data actually exists until after I solved
I am not even sure whether the title of my question is correct, but

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.