Created
June 1, 2022 12:16
-
-
Save DanielAdeniji/34b92424334c28c39f9e9cca814bd8dd to your computer and use it in GitHub Desktop.
Printing out the contents of a string collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System; | |
using System.Linq; | |
class Program | |
{ | |
enum enumConversionChoice | |
{ | |
convertToStringArray | |
, convertToIEnumerable | |
}; | |
static void Main() | |
{ | |
Console.WriteLine | |
( | |
prepareFilelistUsingStringCollectionConverted | |
( | |
enumConversionChoice.convertToStringArray | |
) | |
); | |
Console.WriteLine(""); | |
Console.WriteLine(""); | |
Console.WriteLine | |
( | |
prepareFilelistUsingStringCollectionConverted | |
( | |
enumConversionChoice.convertToIEnumerable | |
) | |
); | |
} | |
private static String prepareFilelistUsingStringCollectionConverted | |
( | |
enumConversionChoice choice | |
) | |
{ | |
String strListofFileNames = ""; | |
System.Collections.Specialized.StringCollection objListofFiles | |
= new System.Collections.Specialized.StringCollection(); | |
objListofFiles.Add("file -01"); | |
objListofFiles.Add("file -02"); | |
if (choice == enumConversionChoice.convertToStringArray) | |
{ | |
string[] strArray; | |
strArray = new string[objListofFiles.Count]; | |
objListofFiles.CopyTo(strArray,0); | |
strListofFileNames | |
= string.Join | |
( | |
System.Environment.NewLine | |
, strArray | |
); | |
} | |
else if (choice == enumConversionChoice.convertToIEnumerable) | |
{ | |
System.Collections.Generic.List<string> listString = null; | |
listString = objListofFiles.Cast<String>().ToList(); | |
strListofFileNames | |
= string.Join | |
( | |
System.Environment.NewLine | |
, listString | |
); | |
} | |
return (strListofFileNames); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment