Convert object to list<string> c#

Francisco Ojeda (CL) 1 Reputation point
2021-10-15T22:16:19.85+00:00

Hi,

Can help me with the next conversion, I'm trying to convert a custom object to list<string>, I have the next parameter like list object, I'm working with asp.net core 3.1.

140910-image.png

when convert with the next statement of code the result is

List<string> fields = listmetadata.Select(s => new { s.Values }).Select(a => a.Values.ToString()).ToList();  
  

140880-2.png

Developer technologies ASP.NET ASP.NET Core
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2021-10-15T22:49:34.607+00:00

    the ToString() method of an object returns the type name. so you are building a list of type names. you object appear to ne

        var fields = new object[]
        {
                new string[] {"a","b"}, 
                new int[] {1,2,3}
        }; 
    

    as its two arrays of different types, what was the output List<string> supposed to be?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.