Does c# have anything comparable to Python's list comprehensions

I want to generate a list in C#. I am missing python's list comprehensions. Is there a c# way to create collections on the fly like list comprehensions or generator statements do in python?

Answers


If you are using C# 3.0 (VS2008) then LINQ to Objects can do very similar things:

List<Foo> fooList = new List<Foo>();
IEnumerable<Foo> extract = from foo in fooList where foo.Bar > 10 select Foo.Name.ToUpper();

Need Your Help

Why does selectionBinding on Ember.Select not respect contentBinding when Ember.Select is not subclassed?

ember.js

When I subclass Ember.Select the selection binding can successfully be set to 'content.selection' where content is a controller. When I try to do this inline in a template, the binding does not con...

com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 15))

java xml-parsing axiom

I am extracting data from a XML using the axiom. But I'm getting above error because of having CTRL-CHAR (eg : â, €, ¢, “, ”, ™, ’, – etc) in the XML. Can any body help me to replace all the CTRL-S...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.