我有問題理解的說法this flowDocument doc
在下面的方法:C#「this」關鍵字如何在靜態方法中限定參數?
public static FormattedText GetFormattedText(this FlowDocument doc)
{
if (doc == null)
{
throw new ArgumentNullException("doc");
}
...
}
調用方不調用上述方法時指定一個參數:
myRichTextBox.TextChanged +=
new TextChangedEventHandler((o, e) => myRichTextBox.Width =
myRichTextBox.Document.GetFormattedText().WidthIncludingTrailingWhitespace + 20);
我肯定的方法不是創建doc
本身。我以前沒有見過用這種方式使用this
。
它的擴展方法 – thumbmunkeys