Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 4:07am

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);
 
Share this answer
 
Simple: just declare the method appropriately:
C#
string documentProvider(ProbablyAStringButIDontKnowForSure message, List<string> filenames
   {
   ...
   }
Or
C#
string documentProvider(ProbablyAStringButIDontKnowForSure message, IEnumerable<string> filenames
   {
   ...
   }
And then call it:
C#
List<string> filenames = new List<string>();
...
string result = documentProvider(myMessage, filenames);
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900