Hi I have the following code and I know Message.To is a collection, just getting to grips with c# - just can't get the syntax right!

string sToAddress = "";
sToAddress = Message.To(0).ToString;

I think I should have added:

System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();


Edited 3 Years Ago by mike_2000_17: Fixed formatting

The error message you are getting actually kind-of tells you specifically what's wrong there... "non-invocable member 'sytem.net.mailmessage.to' cannot be used like a method" means that:


cannot be used in that way. The "To" component of Message cannot accept variables directly.

Were you perhaps going for

string sToAddress = "";
sToAddress = Message.To[0].ToString();

with special attention on the square brackets instead of rounded brackets.

Keep in mind, I haven't tested this snippet, but I made a couple of educated guesses based on what you had provided.

Hope this helps :) Please remember to mark as solved once the issue has been resolved.

Lusiphur: Thanks, very educated. Square brackets fixed the compiler error - now to step through to check it produces what I expect!

This question has already been answered. Start a new discussion instead.