为什么我得到CS1012:"在性格字符太多文字"和CS0019? [英] Why I'm getting CS1012: "Too many characters in character literal" and CS0019?
问题描述
在试图东西上传到Imgur,我必须把一个授权。我与 WebRequest.Headers
做的,但它给了我三个错误。
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倍CS1012误差
2 times CS1012 error
在字符字符太多文字
和1次CS0019错误:
and 1 time CS0019 error:
运算符+不能应用于类型为字符和方法组的操作数
Operator '+' cannot be applied to operands of type 'char' and 'method group'
这是代码:
webRequest.Headers['Authorization'] = 'Bearer ' + GetToken;
我做了什么错,我怎么能解决这个问题,它是如何工作的?
这是与Imgur上传,我不知道如果'为gettoken'的事情是正确的,但它得到的accessToken,这应该正确,如果我的工作权利。
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#中无效。单引号是的字符的文本(字符
)。您需要为字符串双引号。您还需要括号的方法调用:
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();
(注意,这已经无关imgur或的WebRequest $ 。C $ C> - 它只是普通的C#)
(Note that this has nothing to do with imgur or WebRequest
- it's just normal C#.)
链接到MSDN的解释与样本:
Links to MSDN explanations with samples:
- CS1012 - "Too many characters in character literal"
- CS0019 - "Operator 'operator' cannot be applied to operands of type 'type' and 'type'"
这篇关于为什么我得到CS1012:"在性格字符太多文字"和CS0019?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!