Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

教程部分委托链代码注释有问题 #3

Closed
sprders opened this issue Sep 12, 2023 · 5 comments
Closed

教程部分委托链代码注释有问题 #3

sprders opened this issue Sep 12, 2023 · 5 comments

Comments

@sprders
Copy link

sprders commented Sep 12, 2023

delegate int CalculateDelegate(int x, int y);

class Program
{
    static int Add(int x, int y)
    {
        return x + y;
    }

    static int Multiply(int x, int y)
    {
        return x * y;
    }

    static void Main(string[] args)
    {
        CalculateDelegate addDelegate = new CalculateDelegate(Add);
        CalculateDelegate multiplyDelegate = new CalculateDelegate(Multiply);

        CalculateDelegate chainDelegate = addDelegate + multiplyDelegate;

        int result = chainDelegate(2, 3);

        Console.WriteLine(result);  // 输出:8
    }
}

dotnet版本:7.0.304

输出结果是 6,不是 8

@786744873
Copy link
Collaborator

这里确实是个bug,稍后会更新,感谢指出🍻❤️

@786744873
Copy link
Collaborator

大佬你可以pr下,一起参与贡献

@sprders
Copy link
Author

sprders commented Sep 12, 2023

大佬你可以pr下,一起参与贡献

提issue也是一样做贡献嘛😊。
另外,刚才又发现了一个问题,教程部分索引器的注意事项的第一条:

索引器可以有多个参数,但它们的类型必须不同。例如,this[int i, int j] 是有效的,但 this[int i, int i] 是无效的。

前面说的是类型必须不同,但是随后的例子强调的是参数名必须相同参数类型可以相同

Frankozay added a commit to Frankozay/easy-dotnet that referenced this issue Sep 13, 2023
@sprders
Copy link
Author

sprders commented Sep 13, 2023

我刚才发现代码下面的文字部分也有错误,输出了结果 8,这里也要改

Frankozay added a commit to Frankozay/easy-dotnet that referenced this issue Sep 13, 2023
@786744873
Copy link
Collaborator

#6 已修复

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants