2014-10-01 46 views
-6

我努力將下面的代碼轉換爲VB。將C#轉換爲VB。掙扎與(陣列:新[]和關鍵字等待)

C#:

UserCredential credential; 
using (var stream = new FileStream(client_Secrets, FileMode.Open, FileAccess.Read)) 
{ 
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets, 
      new[] { YouTubeService.Scope.YoutubeUpload }, 
      "user", 
      CancellationToken.None 
); 
} 

VB:

Using stream = New FileStream(client_Secrets, FileMode.Open, FileAccess.Read) 
    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, 
      New() {YouTubeService.Scope.YoutubeReadonly}, "user", CancellationToken.None, New FileDataStore(Me.[GetType]().ToString())) 
End Using 

我不得不拋出了等待我只是不能得到陣列工作在()中的藍色線段並說類型預計。這是新()

請注意,我是知道的轉換工具,如: http://www.developerfusion.com/tools/convert/csharp-to-vb/

這些不與Array new()和關鍵字幫助恭候我已經厭倦了。

+0

的http:// www.developerfusion.com/tools/convert/csharp-to-vb/ – 2014-10-01 15:53:51

+0

@DmitryLedentsov這是我遇到問題的數組,代碼轉換器不會幫助我已經完成了轉換,它只有數組並等待鍵我不確定VB的等價文字 – Pomster 2014-10-01 15:55:08

+0

'New Object(){YouTubeService.Scope.YoutubeReadonly}'? – 2014-10-01 15:55:30

回答

0

試試這個:

Dim credential As UserCredential 
Using stream = New FileStream(client_Secrets, FileMode.Open, FileAccess.Read) 
    credential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, New() {YouTubeService.Scope.YoutubeUpload}, "user", CancellationToken.None) 
End Using 
+0

等待關鍵詞在VB中不存在,您還添加了new(),這也是不起作用的。 – Pomster 2014-10-01 16:08:06

+1

@Pomster - 等待當然確實存在。看看這裏:http://msdn.microsoft.com/en-us/library/hh156570.aspx – Icemanind 2014-10-01 16:09:04

+0

@Pomster - 如果編譯器告訴你它不存在 – Icemanind 2014-10-01 16:11:03

0

的VB相當於如下 - 有沒有 「新的()」:

Using stream = New FileStream(client_Secrets, FileMode.Open, FileAccess.Read) 
    credential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, { YouTubeService.Scope.YoutubeUpload }, "user", CancellationToken.None) 
End Using 

我不明白爲什麼你不得不省略了「等待」。你能解釋一下嗎?

+0

這是插入await時發生的錯誤。 '等待'沒有被宣佈。由於其保護級別,它可能無法訪問。 – Pomster 2014-10-01 16:09:44

+0

@Pomster:我明白了 - 您在2012年之前使用的是VB的某些版本。 – 2014-10-01 16:11:09

+0

我正在使用VS2010 – Pomster 2014-10-01 16:13:29

0

昏暗的範圍作爲IList的(字符串)=新的列表(字符串)()

scopes.Add(Google.Apis.YouTube.v3.YouTubeService.Scope.YoutubeReadonly) 

    Dim credential As UserCredential 
    Using stream = New FileStream("client_secret.json", FileMode.Open, FileAccess.Read) 
     credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
       GoogleClientSecrets.Load(stream).Secrets, scopes, "user", CancellationToken.None, 
       New FileDataStore("YouTubeService.VB.Sample")).Result 
    End Using 

這工作,因爲我從谷歌得到它,把它調整到我的需要