static RelatedPosts()
{
Post.Saved += new EventHandler<SavedEventArgs>(Post_Saved);
}
static void Post_Saved(object sender, SavedEventArgs e)
{
if (e.Action == SaveAction.Update)
{
Post post = (Post)sender;
if (_Cache.ContainsKey(post.Id))
_Cache.Remove(post.Id);
}
}
我轉換爲:你可以將其轉換爲VB嗎?
Shared Sub New()
Post.Saved += New EventHandler(Of SavedEventArgs)(AddressOf Post_Saved)
End Sub
Private Shared Sub Post_Saved(ByVal sender As Object, ByVal e As SavedEventArgs)
If e.Action = SaveAction.Update Then
Dim post As Post = DirectCast(sender, Post)
If _Cache.ContainsKey(post.Id) Then
_Cache.Remove(post.Id)
End If
End If
End Sub
但它給我一個錯誤:
公共共享事件保存()是一個事件,不能直接調用。使用'RaiseEvent'語句來引發一個事件。
您未在該代碼中調用任何事件。你可以發佈錯誤發生的代碼嗎? – Guffa 2010-08-16 11:33:29
我同意@Guffa,您發佈的代碼看起來很好。 – Walter 2010-08-16 11:47:12