Friday

C#(csharp) how to resize array (shrink) by Array.Copy

 

/// <summary>
/// Emails addresses creating.
/// </summary>
/// <param name="incom">The incoming array</param>
/// <returns></returns>
private EmailAddressType[] EmailAddressCreate(string[] incom) {
if (incom == null) return null;
EmailAddressType[] ret = new EmailAddressType[incom.Length];
EmailAddressType[] rt;
int i = 0;
foreach (string s in incom) {
if (!string.IsNullOrEmpty(s))
{
ret[i] = new EmailAddressType();
ret[i].EmailAddress = s;
i++;
}
}
// change size of array
if (i < incom.Length)
{
rt = new EmailAddressType[incom.Length];
Array.Copy(rt, ret, i);
}else
{
rt=ret;
}

return rt;
}

more...

No comments:

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...