你们中的许多人都熟悉Josh Smith。他在解释事物方面做得很出色,但是他在文章中做了一个特别的陈述:
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
让我感到困惑...
关于ICommand
和RelayCommand
类,他提到:
One possible implementation pattern is to create a private nested class within the ViewModel class, so that the command has access to private members of its containing ViewModel and does not pollute the namespace.
也许因为我是新手,所以我很难想象他在说什么。有人可以给我发送一些伪代码来解释这个吗?我认为看到代码将帮助我掌握概念。
最佳答案
class Foo
{
private static int f;
private class Bar // nested class
{
void B()
{
int b = f; // access to private member of containing class
}
}
}
但请注意,本文仍在继续使用中。
关于c# - 乔什·史密斯文章的解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9673872/