Skip to content

Instantly share code, notes, and snippets.

@DanielAdeniji
Created June 1, 2022 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielAdeniji/34b92424334c28c39f9e9cca814bd8dd to your computer and use it in GitHub Desktop.
Save DanielAdeniji/34b92424334c28c39f9e9cca814bd8dd to your computer and use it in GitHub Desktop.
Printing out the contents of a string collection
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