Click here to Skip to main content
14,427,400 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a list of files that I am adding a date stamp to each file when it loops. Now I have successfully looped through each file and i want to pass a list of file names as a parameter to another function.

Looping through each file
List<string> filenames = new List<string>();
            foreach (var xx in resultCollection)
            {
                if(xx != null)
                {
                    filenames.Add(xx.MetaData.AccountNumber +"-"+ DateTime.Now);
                }
                
            }


What I have tried:

Now I want to pass the list object as a parameter to this below

<pre>string documentPath = documentProvider(message,List<string> filenames);


I want to pass filenames. How can I do that?
Posted
Updated 14-Jan-20 5:07am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Your documentProvider method will need to be like

private string documentProvider (string message, List<string> filenames)
{
    // I am assuming message is a string, change the type as required
    // code here
}


call the function like


string documentPath = documentProvider(message, filenames);
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Simple: just declare the method appropriately:
string documentProvider(ProbablyAStringButIDontKnowForSure message, List<string> filenames
   {
   ...
   }
Or
string documentProvider(ProbablyAStringButIDontKnowForSure message, IEnumerable<string> filenames
   {
   ...
   }
And then call it:
List<string> filenames = new List<string>();
...
string result = documentProvider(myMessage, filenames);
   
Comments
Nkhanedzeni 16-Jan-20 8:35am
   
Thank you, it worked like a champ

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100