0

Variable.cs

 public string[] CcEmails { get; set; }

Mail.cs

  EDTO.CcEmails = dr["rsh_ccmail"].ToString().Split(';');

here i got two strings eg. [email protected] ; [email protected]

MailProcess.cs

dataRPT1=get data from sql
EDTO.CcEmails = new string[dataRPT1.Rows.Count];
                    for (int i = 0; i < dataRPT1.Rows.Count; i++)
                    {
                        EDTO.CcEmails[i] = dataRPT1.Rows[i]["email_addr"].ToString();
                    }

Here i got list of string [email protected] ...... I am try to add with existing but it add only new values..Anyone could help me..

1
  • If EDTO.CcEmails is an array, why are you using ToString to flatten the array? Why not just use it as an array? Commented Jun 6, 2018 at 8:01

2 Answers 2

1

I tend to use union, although that will remove duplicate entries. But to keep all entries you can use Concat on the array.

        var emailString = "[email protected];[email protected]";
        string[] emails = emailString.Split(';');

        string[] emailsFromSQL = new string[3];
        emailsFromSQL[0] = "[email protected]";
        emailsFromSQL[1] = "[email protected]";
        emailsFromSQL[2] = "[email protected]";

        //No Duplicates
        var combined = emails.Union(emailsFromSQL).ToArray();

        //Duplicates
        var allCombined = emails.Concat(emailsFromSQL).ToArray();

Thanks

Sign up to request clarification or add additional context in comments.

Comments

1

I find the easiest way of doing this is to create a list, add items to the list, then use string.Join to create the new string.

var items = new List<string>();
for (int i = 0; i < dataRPT1.Rows.Count; i++)
{
    items.Add(dataRPT1.Rows[i]["email_addr"].ToString());
}

EDTO.CcEmails = string.Join(";", items);

Update after changed question:

If the type of the CcEmails is an array, the last line could be:

EDTO.CcEmails = items.ToArray();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.