Passing multiple fields with multiple values in and out of functions in C#

Posted by Stephen on November 9, 2014 in C#, Programming |
java-2-104272-m (1)

I recently had a project where I had to acquire and manipulate a entire inbox worth of e-mails.  I needed to capture the Subject, Body, To, From, CC, and BCC of each email. I also wanted to  keep all the e-mails together  and process them as  group.

To do this I started with a custom data structure using the struct command like this:

public struct EmailTemplate
public string To;
public string From;
public string CC;
public string BCC;
public string Attachment;
public string Subject;
public string Body;

This creates a single object (called EmailTemplate) with different properties that contain the values for the different parts of the e-mail (body, subject, from, etc)


The next step is to create use the list<> data type to define a list variable.  This will essentially define a list of EmailTemplate objects.  It should look like this:

List<EmailTemplate> EmailList= new List<EmailTemplate>();

Now we have one List object (called “EmailList”) that is a list of EmailTemplate objects. We can now build a function to deal with all emails in the list as a set.


public List<EmailTemplate> EmailListOut (List<EmailTemplate> EMailListIn)
List<EmailTemplate> ProcessedEmails= new List<EmailTemplate>();
//Process emails and add them to this list ^

//Output this list:

return ProcessedEmails;


The above is an example of how you would create a function to accept a list of custom struct objects and return a list of custom struct objects.

I hope you find this helpfull

Happy Coding.

Tags: , , , ,

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Copyright © 2014-2020 StephensProjects.com All rights reserved.
This site is using the Multi Child-Theme, v2.1.3, on top of
the Parent-Theme Desk Mess Mirrored, v2.3, from BuyNowShop.com.