Click here to Skip to main content
15,912,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have to send a email and i have email code. In that there are parameters (like email address, a, b and etc). So while sending the email, it is taking the info from parameters. My doubt is
C#
public static void SendEmail(string FirstName, string LastName, string emailAddress, string BODY, string TASKID)


In the above mentioned line, i have used string emailAddress as one of the parameter and i have written the code to get the email address in other page as shown below:


C#
List<String> updateAddresses = new List<String>();
            foreach (var person in personResults.Results)
            {
                string addr = null;

                addr = person.Artifact.Fields.Single(
                        field => field.Guids.Contains(GUIDCollection.EMAIL_ADDRESS_GUID)
                    ).ValueAsFixedLengthText;

                if ((addr != null) && (addr != ""))
                {
                    updateAddresses.Add(addr);
                }
            }


So now, if do emailAddress = updatedAddress.Add(addr), it is giving error. Now how to get the value into emailAddress string? Any help would be appreciated.

What I have tried:

Tried renaming the string addr to emailAddress. Not sure whether it is correct or not.
Posted
Updated 13-Sep-16 1:08am
Comments
ZurdoDev 13-Sep-16 7:04am    
The error message will tell you, and us, what the problem is. Please click Improve question and add the error message.

1 solution

When you declare a method, like your SendEmail method, you provide parameters which consist of the type of the data, and the name of a variable to store the data in.
It's just like you had this inline code:
C#
string myName = "OriginalGriff";
string yourName = "Member 8010354";
...
string userName = myName;
username = "The user's name is: " + userName;
Console.WriteLine(userName);
...
username = yourname;
username = "The user's name is: " + userName;
Console.Writeline(username);
...
You could take the "common code" and make that a method:
C#
public void ShowUsername(string userName)
   {
   username = "The user's name is: " + userName;
   Console.Writeline(username);
   }
...
string myName = "OriginalGriff";
string yourName = "Member 8010354";
ShowUsername(myName);
ShowUsername(yourName);
The name of the parameter variable is only relevant inside the method, it can't be accessed outside.

In your case, all you have to do is call SendEmail and pass it the relevant parameter data:
C#
SendEmail("Original", "Griff", originalGriffEmailAddress, "Hello!", "I have no idea what a task id is");
As long as the variable originalGriffEmailAddress exists and holds my email address as a string, it'll work.

More specific than that I can't be: you don't show where you call the method, or where that foreach loop code you show fits into your program.
 
Share this answer
 
Comments
Maciej Los 13-Sep-16 10:58am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900