Why I'm getting CS1012: “Too many characters i

2019-01-07 00:18发布

When trying to upload something to Imgur, I have to put an Authorization in. I do it with WebRequest.Headers but it gives me three errors.

2 times CS1012 error

Too many characters in character literal

and 1 time CS0019 error:

Operator '+' cannot be applied to operands of type 'char' and 'method group'

This is the code:

webRequest.Headers['Authorization'] = 'Bearer ' + GetToken;

What have I done wrong, how can I fix it, and how does it work? This is uploading with Imgur, I don't know if the 'GetToken' thing is right but it's to get the AccessToken, which should work correctly if I'm right.

标签: c# imgur
1条回答
戒情不戒烟
2楼-- · 2019-01-07 00:47

You're trying to use single quotes for string literals - that's invalid in C#. Single quotes are for character literals (char). You need double quotes for string literals. You also need parentheses for a method call:

webRequest.Headers["Authorization"] = "Bearer " + GetToken();

(Note that this has nothing to do with imgur or WebRequest - it's just normal C#.)

Links to MSDN explanations with samples:

查看更多
登录 后发表回答