---
title: "C# Dynamic select List of strings"  
description: "C# Dynamic select List of strings"  
author: "Anonymous User"  
published: 2015-12-09  
updated: 2015-12-09  
canonical: https://www.mindstick.com/forum/33704/c-sharp-dynamic-select-list-of-strings  
category: ".net"  
tags: ["c#", ".net", "string", "list"]  
reading_time: 1 minute  

---

# C# Dynamic select List of strings

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to get List of [strings](https://www.mindstick.com/forum/161912/explain-the-python-strings) from my [dynamic object](https://www.mindstick.com/forum/872/how-to-serialize-list-property-of-a-dynamic-object) list and it keeps saying that:\

```
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<dynamic>' to 'System.Collections.Generic.List<string>'
```

I'm selecting a [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) and use .[ToString](https://www.mindstick.com/interview/2259/what-is-the-difference-between-tostring-convert-tostring)() on it:\

```
var objects = new List<dynamic>();//filling objects here
```

\

```
List<string> things = objects.Select(x => x.nameref.ToString()).ToList();
```

So isn't it a valid List of strings? Why [compiler](https://www.mindstick.com/articles/27/just-in-time-compiler) is assuming that this list is of type dynamic?\
I've tried also converting from this answer, but it keeps [giving](https://yourviews.mindstick.com/view/80639/regifting-is-far-better-than-giving-away-a-bouquet) me same error.\
[Anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) knows how to make it List<[string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)>?\
Why isn't it working? Because you can make mess like this:\

```
public class Test{    public int ToString()    {        return 0;    }}
```

and compiler won't know if ToString returns string or int.

## Replies

### Reply by Anonymous User

You need to cast the items, like so:\

```
List<string> things = objects.Select(x => x.nameref.ToString()).Cast<string>().ToList();
```

The reason why it's not recognizing that ToString() returns a string is that it's called on a [dynamic](https://www.mindstick.com/blog/11080/features-of-java-dynamic-complied-and-interpreted) object, and the method binding is done at runtime, not compile time.


---

Original Source: https://www.mindstick.com/forum/33704/c-sharp-dynamic-select-list-of-strings

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
