Best practice when converting DataColumn values to an array of strings?
[Edit]
All values for certain DataColumn for all DataTable rows to be converted to an array of string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If I understood your goal you want to specify a particular column and return all its values as a string array.
Try these approaches out:
You could replace
columnIndexwithcolumnNameinstead, for example:EDIT: you’ve asked for a string array specifically but in case you’re flexible about the requirements I would prefer a
List<string>to avoid the need to determine the array length prior to the for loop in the first example and simply add items to it. It’s also a good opportunity to use a foreach loop instead.I would then rewrite the code as follows: