Ray Suelzer
Ray Suelzer

Reputation: 4107

Using byVal in C#..... a little complicated

In 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#:

    protected virtual string AuthorizationHeaderValue
    {
        get { return string.Format("{0} {1}:{2}", AuthorizationHeaderSignaturePrefix, APIIdentifier, signature); }
    }

I am getting this error in 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).

Ideas?

Upvotes: 0

Views: 226

Answers (1)

Eric J.
Eric J.

Reputation: 150138

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# does not allow properties to have parameters as VB.Net does (except for one indexer per class). Consider converting it to a method.

protected virtual string AuthorizationHeaderValue(string signature)
{
    return string.Format("{0} {1}:{2}", AuthorizationHeaderSignaturePrefix, 
          APIIdentifier, signature);
}

Upvotes: 3

Related Questions