[英]Using byVal in C#… a little complicated
In VB 在VB中
Protected Overridable ReadOnly Property AuthorizationHeaderValue(ByVal signature As String) As String
Get
Return String.Format("{0} {1}:{2}", AuthorizationHeaderSignaturePrefix, APIIdentifier, signature)
End Get
End Property
What I have in C#: 我在C#中拥有什么:
protected virtual string AuthorizationHeaderValue
{
get { return string.Format("{0} {1}:{2}", AuthorizationHeaderSignaturePrefix, APIIdentifier, signature); }
}
I am getting this error in C#: 我在C#中收到此错误:
The name 'signature' does not exist in the current context... 名称“签名”在当前上下文中不存在...
which to me seems obvious since when I convert the code it drops the ( ByVal signature as String
). 在我看来,这很明显,因为当我转换代码时,它会丢弃( ByVal signature as String
)。
Ideas? 有想法吗?
The problem with your C# code is that the property body expects a variable signature but you do not define a variable with that name. C#代码的问题在于属性主体需要变量签名,但是您没有使用该名称定义变量。
C# does not allow properties to have parameters as VB.Net does (except for one indexer per class). C#不允许属性像VB.Net一样具有参数(每个类一个索引器除外)。 Consider converting it to a method. 考虑将其转换为方法。
protected virtual string AuthorizationHeaderValue(string signature)
{
return string.Format("{0} {1}:{2}", AuthorizationHeaderSignaturePrefix,
APIIdentifier, signature);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.