将此作为静态方法中的参数传递

我在使用Visual C#中的一些代码遇到一些问题对于Windows Phone问题不在于它不起作用,因为它确实如此,但我不明白如何在静态类中创建一个静态方法,其中给自己一个参数:

public static void MethodONe( this Timeline animation ) { //this class does not extend the TimeLine class, and is not connected to it in any //such way. animation.MethodTwo( ); } public static void MethodTwo( this Timeline animation ) { someCode( ); } 

这个参数传递是如何被调用的,它究竟是做什么的?

这是对Timeline对象的所谓扩展方法。 它增加了function,而无需修改类本身。

http://msdn.microsoft.com/en-us/library/bb383977.aspx

在您的情况下,animation参数是Timeline对象(调用函数):

 var timeLine = new Timeline(); timeLine.MethodTwo(); 

因此timeLine对象将作为动画参数传递给函数。 在维基百科上有一篇很好的文章,它更详细地解释了它:

http://en.wikipedia.org/wiki/Extension_method