Question

I have this SortedDictionary:

var signature_parameters = new SortedDictionary<string, string>
{
    { "oauth_callback", SocialEngine.twitter_aggrega_redirect_uri },
    { "oauth_consumer_key", SocialEngine.twitter_aggrega_consumer_key },
};

now I tried this:

var header_parameters = signature_parameters.Add("oauth_signature", Uri.EscapeDataString(oauth_signature));

but it says I can't assign a void variable to a implicit method.

Where am I wrong?

Was it helpful?

Solution

Where am I wrong?

You're calling the Add method, but expecting it to return something. It doesn't.

If you're trying to create a new dictionary with the same entries and one new one, you probably want:

var headerParameters = new SortedDictionary<string, string>(signatureParameters)
{
    "oauth_signature", Uri.EscapeDataString(oauth_signature)
};

The constructor will create a copy of the existing dictionary, then the collection initializer will add the key/value pair just to the new one.

OTHER TIPS

Add method adds item to dictionary, but returns nothing, so you can't assign result of Add method to variable.

signature_parameters.Add("oauth_signature", Uri.EscapeDataString(oauth_signature))

You can assign it later, but because it is a reference type, you'll just copy the reference.

var header_parameters = signature_parameters;

Add is a void method since it adds an item to the dictionary but it does not return something.

So change this

var header_parameters = signature_parameters.Add("oauth_signature", Uri.EscapeDataString(oauth_signature));

to

var header_parameters = new KeyValuePair<string, string>("oauth_signature", Uri.EscapeDataString(oauth_signature));
signature_parameters.Add(header_parameters.Key, header_parameters.Value);

( assuming that you want to have the last inserted KeyValuePair )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top