2017-02-10 139 views
-1

我在C#中新有这样的变种:
如何设置初始化var c#?

var updates = await Bot.GetUpdatesAsync(offset); 


但现在要更新定义其他范围,并用这种形状使用它:

updates = await Bot.GetUpdatesAsync(offset); 


尝试定义此代码:

var updates =(string) null; 


但在这行C#编译器收到此错误:

updates = await Bot.GetUpdatesAsync(offset); 
(awaitable)Task<Update[]> TelegramBotClient.GetUpdatesAsync([int offset=0],[int limit=100],[int timeout=0],[CancellationToken cancellationToken=default(CancellationToken) 
use this method recieve incoming updates using long polling. 
Usage: 
Update[] x=await GetUpdateAsync(...); 
Can not implicitly convert type 'Telegram.Bot.Types.Update[]' to 'string' 


我怎样才能解决这个代码感谢:

var updates =(string) null; 
+0

当然更换var updates =(string) null;如果你设置'var'为'string'它不会转换'Telegram.Bot.Types.Update [ ]'到'string'并且会抛出错误。 – Mairaj

回答

0

var updates =(Telegram.Bot.Types.Update[]) null;

+0

使用'var'关键字进行隐式输入的目的是让代码更短,更具可读性。但'var updates =(Telegram.Bot.Types.Update [])null;'比'Telegram.Bot.Types.Update []更新'更不可读并且比显式类型更长'',所以我不会推荐'var'这样。 –

+0

同意安迪。我们可以将它声明为Telegram.Bot.Types.Update []更新; –

0

显然,你的方法的返回类型是不是string,但Telegram.Bot.Types.Update[]

所以,你可以更改代码以

Telegram.Bot.Types.Update[] updates; 
// the rest of code 
updates = await Bot.GetUpdatesAsync(offset); 
+0

感谢您的帮助我的朋友 –

+0

9分钟后接受您的回答 –