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;

Recommended Answers

All 3 Replies

I think I should have added:

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

sorry...

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:

Message.To(0).ToString;

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.