2010-06-09 58 views
0

我可以在VB中實現以下C#代碼片段,但它看起來非常笨重,因爲我執行Linq查詢來獲取相關用戶的事件。有一條整潔的道路嗎?C#VB問題

  ctx.FetchEventsForWhichCurrentUserIsRegistered((op) => 
      { 
       if (!op.HasError) 
       { 
        var items = op.Value; 
        _currentUserRegisteredEventIds = new HashSet<int>(items); 
        UpdateRegistrationButtons(); 
       } 
      }, null); 
     } 
     else 
     { 
      _currentUserRegisteredEventIds = null; 
      UpdateRegistrationButtons(); 
     } 
+0

什麼版本的.Net? vb支持.Net 4/vs2010中的多行lambdas。 – 2010-06-09 16:36:12

+0

.NET 4.我的問題是,我不明白var items = op.value指的是什麼。 – Jim 2010-06-10 09:05:11

回答

1
ctx.FetchEventsForWhichCurrentUserIsRegistered(Function(op) Do 
    If Not op.HasError Then 
     Dim items = op.Value 
     _currentUserRegisteredEventIds = New HashSet(Of Integer)(items) 
     UpdateRegistrationButtons() 
    End If 
End Function, Nothing) 

我發現下面的Web應用程序來爲這個有用: http://www.developerfusion.com/tools/convert/vb-to-csharp/

雖然一些小的調整,有時是需要

+0

感謝這一點,但我也使用了您提到的網站以及http://converter.telerik.com/。可悲的是,這兩個網站的解決方案都不起作用。 – Jim 2010-06-09 16:48:33

0

反射總是有用的這 - 編譯代碼,然後反彙編並轉換爲您選擇的語言。我沒有親自使用過,但是這個加載項似乎甚至將代碼導出到一個項目中:http://filegenreflector.codeplex.com/

+0

謝謝你,但我不確定我想通過嘗試一種我沒有專業知識的技術來挑戰我有限的技能! – Jim 2010-06-09 17:56:36

+0

嘿吉姆 - 反射器是你從哪裏得到你的技能! http://www.red-gate.com/products/reflector/ 將您的代碼放入Visual Studio項目中,構建它,然後使用Reflector打開已編譯的程序集 - 您可以將代碼轉換爲c#或vb。淨。 值得投入一些時間... – TobyEvans 2010-06-10 22:07:34