---
title: "Return list of string from list nested in a list"  
description: "Return list of string from list nested in a list"  
author: "Anonymous User"  
published: 2013-12-12  
updated: 2013-12-12  
canonical: https://www.mindstick.com/forum/1767/return-list-of-string-from-list-nested-in-a-list  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Return list of string from list nested in a list

I have three classes; State, County, and City. State contains a list of County. County contains a list of City.

```
public class State{  public string StateCode;  List<County> Counties;  List<string> CitiesInState  {    get    {      return //LINQ STATEMENT TO GET LIST OF ALL CITYNAMES FROM LIST OF COUNTIES    }  }} public class County{  public string CountyName;  List<City> Cities;} public class City{  public string CityName;}
```

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to return a list of all CityNames within the State. Since this is a [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) of an [item](https://www.mindstick.com/forum/156564/remove-item-in-an-array-in-javascript) that is in a List which is an item within another List, I'm not sure it is possible. I haven't been able to write anything that will even compile. Is this possible? Can someone point my in the [right direction](https://yourviews.mindstick.com/story/1002/daily-30-minutes-in-the-right-direction-can-change-the-entire-day-s-mood)?

## Replies

### Reply by Pravesh Singh

Hi Tanuj,\
\

You're asking how to flatten a nested list:

Counties.SelectMany(c => c.Cities).Select(c => c.CityName)


---

Original Source: https://www.mindstick.com/forum/1767/return-list-of-string-from-list-nested-in-a-list

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
