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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:41:32+00:00 2026-05-13T15:41:32+00:00

I have the following static function in c# public static string Greet(string name) {

  • 0

I have the following static function in c#

public static string Greet(string name)
    {
        string greeting = "welcome  ";

        // is it possible to pass this value to a label outside this static method?
        string concat = string.Concat(greeting, name);

        //error
        Label1.text = concat;

        //I want to return only the name
        return name;
    }

As you can see in the comments, I want to retain only the name as the return value, however I want to be able to take out the value of the concat variable to asign it to a label, but when i try the compiler refuses, can it be done? Is there a work around?

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-05-13T15:41:33+00:00Added an answer on May 13, 2026 at 3:41 pm

    If the method must be static for some reason, the main approach here would be to pass any required state into the method – i.e. add a parameter to the method that is either the label or (better) some typed wrapper with a settable property like .Greeting:

    public static string Greet(string name, YourType whatever)
    {
        string greeting = "welcome  ";
    
        whatever.Greeting = string.Concat(greeting, name);
    
        return name;
    }
    

    (where YourType could be your control, or could be an interface allowing re-use)

    What you don’t want to do is use static state or events – very easy to get memory leaks etc that way.


    For example:

    public static string Greet(string name, IGreetable whatever)
    {
        string greeting = "welcome  ";
    
        whatever.Greeting = string.Concat(greeting, name);
    
        return name;
    }
    public interface IGreetable {
        string Greeting {get;set;}
    }
    public class MyForm : Form, IGreetable {
        // snip some designer code
    
        public string Greeting {
            get { return helloLabel.Text;}
            set { helloLabel.Text = value;}
        }
    
        public void SayHello() {
            Greet("Fred", this);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 306k
  • Answers 306k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From Choose Toolbox Items: An error occurred loading this property… May 13, 2026 at 9:23 pm
  • Editorial Team
    Editorial Team added an answer Change your UpdateParamters section like this: <UpdateParameters> <asp:Parameter Name="TaskName" Type="String"… May 13, 2026 at 9:23 pm
  • Editorial Team
    Editorial Team added an answer To avoid making mistakes, you can use Calendar static values… May 13, 2026 at 9:23 pm

Related Questions

I have the following function in C++ managed (ref) class: public static void Transform(Bitmap^
If I have the following function, it is considered pure in that it has
I'm writing a little C# app that calls a few functions in a C++
I have recreated the Predicatebuilder class in a seperate C# project and I'm trying
I have a exported function in a c++ DLL // C++ DLL (Blarggg.dll) extern

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.