-3

How to rewrite the following in another way?

 OAuthRequestToken requestToken = new OAuthRequestToken { Token = OauthToken };
001
  • 62,807
  • 94
  • 230
  • 350

3 Answers3

4

Why yes there is. The real question is why would you want to write extra code when the compiler can do it for you?

var requestToken = new OAuthRequestToken();
requestToken.Token = OauthToken; 
ChaosPandion
  • 77,506
  • 18
  • 119
  • 157
3

This is equivalent.

OAuthRequestToken requestToken = new OAuthRequestToken();
requestToken.Token =  OauthToken;
John Buchanan
  • 5,054
  • 2
  • 19
  • 17
1

If you just want to know an new way to write , the following code is anohter way...

        OAuthRequestToken requestToken = new OAuthRequestToken();
        requestToken.GetType().GetProperty("Token").SetValue(requestToken, OauthToken, null);
shenhengbin
  • 4,236
  • 1
  • 24
  • 33