小编tik*_*ika的帖子

如何将C#静态方法中的值赋给标签

我在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;
    }
Run Code Online (Sandbox Code Playgroud)

正如您在注释中看到的,我想只保留名称作为返回值,但是我希望能够取出concat变量的值以将其作为标签,但是当我尝试编译器拒绝时,能做到吗?有工作吗?

谢谢.

c# asp.net methods static

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×1

c# ×1

methods ×1

static ×1