Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 学员应显示文本_C# - Fatal编程技术网

C# 学员应显示文本

C# 学员应显示文本,c#,C#,我在c#中有以下代码: 它应该显示“1”,但它显示了一个错误。ShowDelegate()函数不返回任何值。您需要它从SD委托返回值: public class FClass { public delegate string Show(int n); public string ShowDelegate(Show SD) { return SD(1); } } public class SClass { static string Ret

我在c#中有以下代码:

它应该显示“1”,但它显示了一个错误。

ShowDelegate()
函数不返回任何值。您需要它从
SD
委托返回值:

public class FClass
{
    public delegate string Show(int n);
    public string ShowDelegate(Show SD)
    {
        return SD(1);
    }
}

public class SClass
{
    static string ReturnString(int n)
    {
        return n.ToString();
    }

    static void Main(string[] args)
    {
        FClass fclass = new FClass();
        FClass.Show show = new FClass.Show(ReturnString);
        Console.WriteLine(fclass.ShowDelegate(show));
    }
}
如所述,
ShowDelegate()
函数不返回任何值(void)。您需要它从SD委托返回值或移动
控制台。WriteLine
调用
ShowDelegate
方法:

public class FClass
{
    public delegate string Show(int n);
    public void ShowDelegate(Show SD)
    {
        Console.WriteLine(SD(1)); // <-- Show delegate text
    }
}
public class SClass
{
    static string ReturnString(int n)
    {
        return n.ToString();
    }
    static void Main(string[] args)
    {
        FClass fclass = new FClass();
        FClass.Show show = new FClass.Show(ReturnString);
        fclass.ShowDelegate(show);
        Console.ReadKey();
    }
}
公共类FClass
{
公共委托字符串显示(int n);
公开作废ShowDelegate(显示SD)
{

Console.WriteLine(SD(1));//
ShowDelegate
不返回任何内容-您认为您正在传递给
Console.WriteLine的具体内容是什么?错误是什么?这是您的问题中必须包含的内容。
public class FClass
{
    public delegate string Show(int n);
    public void ShowDelegate(Show SD)
    {
        Console.WriteLine(SD(1)); // <-- Show delegate text
    }
}
public class SClass
{
    static string ReturnString(int n)
    {
        return n.ToString();
    }
    static void Main(string[] args)
    {
        FClass fclass = new FClass();
        FClass.Show show = new FClass.Show(ReturnString);
        fclass.ShowDelegate(show);
        Console.ReadKey();
    }
}