0

I would like to create a class or struct for this message, but I don't know what the following means:

body:,from:,to:,

I know what they are doing on a high-level, but don't know what these words are for or how they would fit into a class.

TwilioClient.Init(accountSid, authToken);
var message = MessageResource.Create(
    body: "Join Earth's mightiest heroes. Like Kevin Bacon.",
    from: new Twillio.Types.PhoneNumber("+1501712261"),
    to:   new Twillio.Types.PhoneNumber("+1501712261") 
)
Pavel Anikhouski
  • 21,776
  • 12
  • 51
  • 66
  • 1
    the names of the parameters of `Create`? Or do you want to know what the **meaning** of those parameters is? – MakePeaceGreatAgain Dec 06 '19 at 09:43
  • 1
    _"I would like to create some class or struct for this message"_ - why? There seems to already _be_ a type for that, namely the one that is returned from `MessageSource.Create`. – Fildor Dec 06 '19 at 09:47
  • Ok, I find out what it is. I don't need to know order of arguments i just set body: to let the method know that i pass this exactly argument. Not sure still hi would class look like –  Dec 06 '19 at 09:48
  • I want create class to send a class as a parameter and not exactly single arguments. Isn't that correct? –  Dec 06 '19 at 09:50
  • 3
    just pass that `message` to whatever method you like. E.g. `DoSomethingWithMessage(message)`. You don´t need an *additional* class, just use the *existing* one – MakePeaceGreatAgain Dec 06 '19 at 09:54
  • Does this answer your question? [C# syntax - Colon after a variable name](https://stackoverflow.com/questions/3283781/c-sharp-syntax-colon-after-a-variable-name) – Sinatr Dec 06 '19 at 10:11
  • Linking [more](https://stackoverflow.com/q/5262634/1997232) and [more](https://stackoverflow.com/q/21613388/1997232) and [more](https://stackoverflow.com/q/24339624/1997232)... see "Linked" part on the right side of the page. – Sinatr Dec 06 '19 at 10:13

2 Answers2

3

This is a named arguments of methods. Basically, you can specify an argument for a parameter by associating the argument with the parameter's name without keeping in mind the order of arguments in parameters list. You can read more at MSDN

Named arguments free you from the need to remember or to look up the order of parameters in the parameter lists of called methods. The parameter for each argument can be specified by parameter name.

Pavel Anikhouski
  • 21,776
  • 12
  • 51
  • 66
1

the body:, from: ? It's the name of the parameters, it makes the call more readable, it allows you provide the arguments in another order, and it has no influence on the performance, it's just syntax sugar.

Holger
  • 2,446
  • 1
  • 14
  • 13