Member_2_3718378
asked on
Converting Generic Lists to Strings using C#
Let's say I have two generic lists: one is a g-list of integers (List<int>) and the other is of a custom class (List<StoredProcedureInfo> ). First, I want to convert the list of integers to a comma-delimited string:
========================== =======
List<int> integerList = new List<int>();
integerList.Add(4);
integerList.Add(132);
integerList.Add(36);
// How do I retrieve the values in [integerList] as a comma-delimited string?
========================== =======
Let's say my custom class, StoredProcedureInfo, has four properties: ID (int), Name (string), Text (string), Checked (bool). Is there an easy way to get all of the ID property values in List<StoredProcedureInfo> as a comma-delimited string?
-= DeathToSpam =-
==========================
List<int> integerList = new List<int>();
integerList.Add(4);
integerList.Add(132);
integerList.Add(36);
// How do I retrieve the values in [integerList] as a comma-delimited string?
==========================
Let's say my custom class, StoredProcedureInfo, has four properties: ID (int), Name (string), Text (string), Checked (bool). Is there an easy way to get all of the ID property values in List<StoredProcedureInfo> as a comma-delimited string?
-= DeathToSpam =-
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi, not that I'm aware of... the String.Join allows you to create a CSV string by specifying a delimiter and a string array whose values will be concatenated into one string (seperated by the delim you specify as the first param)... but there doesnt seem to be a prewritten method that you can use for this type of functionality with generic lists... let alone generic lists with a specific property of the underlying type (like your ID property).
Hope this helps!
Hope this helps!
ASKER
-= DeathToSpam =-