- 浏览: 401250 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
If you are faimiar with Scala, you must have heard or used the function flatMap which is a very useful function that enable you to flat a collection.
There is no such flatMap or Map method as in Scala, however, the C# linq has provide you with the necessary tools to allow you to do the flat map.
this has been discussed in this post "USE LINQ'S SELECTMANY METHOD TO "FLATTEN" COLLECTIONS", it has been discussed.
Below I will save the droll and let's see the code.
class League { public string Name { get; set; } public Team[] Teams { get; set; } } class Team { public string Name { get; set; } public Player[] Players { get; set; } public int NumberOfWins { get; set; } public string HomeState { get; set; } } class Player { public string Name { get; set; } public int Age { get; set; } } class Program { static void Main(string[] args) { var leagues = new List<League> { new League { Name = "AFC-West", Teams = new []{ new Team { Name = "Chargers", NumberOfWins = 3, HomeState = "CA", Players = new [] { new Player { Name = "Rivers", Age = 30 }, new Player { Name = "Tomlinson" , Age = 23}, new Player { Name = "Gates" , Age = 18}, } }, new Team { Name = "Croncos", NumberOfWins = 2, HomeState = "LOS", Players = new [] { new Player { Name = "Culter", Age = 23 }, new Player { Name = "Bailey", Age = 28 }, new Player { Name = "Marshal", Age = 30 }, } }, } }, new League { Name = "AFC-South", Teams = new [] { new Team { NumberOfWins = 1, Name = "Colts", HomeState = "NY", Players = new [] { new Player { Name = "Manning", Age = 31 }, new Player { Name = "Bailey" , Age = 19}, new Player { Name = "Vinatieri" , Age = 26}, } }, } }, }; var allTeams = from t in leagues. SelectMany(l => l.Teams) select t; var allPlayers = from p in leagues .SelectMany(l => l.Teams) .SelectMany(t => t.Players) select p; var onlyYoungPlayers = from p in leagues .SelectMany(l => l.Teams) .SelectMany(t => t.Players) where p.Age < 25 select p; var players = leagues.SelectMany(l => l.Teams) .Where(t => t.NumberOfWins > 2) .Where(p => p.HomeState == "CA") .Select(p => p); var teamsAndTheirLeagues = from helper in leagues .SelectMany(l => l.Teams, (league, team) => new { league, team }) where helper.team.Players.Length > 2 && helper.league.Teams.Length < 10 select new { LeagueID = helper.league.Name, Team = helper.team }; } }
发表评论
-
wpf - example to enhance ComboBox for AutoComplete
2014-09-19 15:56 1979first let’s see an example ... -
Investigate and troubleshoot possible memory leak issue of .NET application
2014-07-31 10:42 0Hi All, I would like to sh ... -
C# – CoerceValueCallback合并、替换元数据值
2013-08-05 21:59 1929Topic: C# – CoerceValueCallbac ... -
wpf – ListView交替背景色
2013-07-02 20:56 6555Wpf – Alternate background col ... -
C# - 简单介绍TaskScheduler
2013-06-29 17:18 12054标题: C# - 简单介绍TaskSchedulerTit ... -
c# - Get enum from enum attribute
2013-06-27 21:32 1253DescriptionAttribute gives the ... -
C# - PInvoke, gotchas on the RegisterClassEx and the CreateWindowEx
2013-06-24 13:49 2576I get an exception message li ... -
c# - Use PInvoke to create simple win32 Application
2013-06-24 11:59 10955In this post, .net platform h ... -
c# - Linq's Select method as the Map function
2013-06-19 18:47 1296If you comes from a functiona ... -
c# - Tips of Linq expression Any to determine if a collection is Empty
2013-06-19 18:29 943When you are @ the linq expres ... -
myth buster - typeof accepting array of types not acceptable
2013-06-19 17:17 819I have seen from some book whe ... -
windows - trying to create WIN32 application with PInvoke
2013-06-19 14:34 0While it is stupid to do such ... -
WPF - Setting foreground color of Entire window
2013-06-13 16:00 1926You might as well as I would s ... -
WPF - Enhanced TabControl - TabControlEx aka Prerendering TabControl
2013-06-13 13:12 5337As an opening word, let's che ... -
wpf - ControlTemplate and AddLogicChild/RemoveLogicalChild
2013-06-10 15:42 1191Recently I was trying to debug ... -
c# - P/Invoke, DllImport, Marshal Structures and Type conversions
2013-06-05 15:25 1717P/Invoke as in the following q ... -
c# - A study on the NativeWindow - encapsulate window handle and procedure
2013-06-05 14:40 6100NativeWindow gives you a way t ... -
WCF - Notify server when client connects
2013-06-03 18:19 1227It is sometimes very importan ... -
wcf - Debug to enable Server exception in Fault message
2013-06-03 15:47 1099WCF will be able to send back ... -
c# - determine if a type/object is serialzable
2013-05-30 16:35 870In WCF, primitives type are s ...
相关推荐
标题提到的"scala-2.12.14.zip&scala-2.12.11.tgz"是Scala的不同版本,针对不同的操作系统进行了打包。Windows用户可以使用".zip"格式的文件,而Linux用户则适合使用".tgz"格式的文件。这里我们主要关注Linux版本的...
赠送jar包:scala-parser-combinators_2.11-1.0.4.jar; 赠送原API文档:scala-parser-combinators_2.11-1.0.4-javadoc.jar; 赠送源代码:scala-parser-combinators_2.11-1.0.4-sources.jar; 包含翻译后的API...
Algorithm-algorithm-implementation-in-java-javascript-scala.zip,本项目的目标是提供Java、JavaScript和斯卡拉的可重用算法集合。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
赠送jar包:scala-compiler-2.11.8.jar; 赠送原API文档:scala-compiler-2.11.8-javadoc.jar; 赠送源代码:scala-compiler-2.11.8-sources.jar; 赠送Maven依赖信息文件:scala-compiler-2.11.8.pom; 包含翻译后...
maven的scala编译包
在Scala-2.11.1.zip这个压缩包中,我们看到的是Scala的特定版本2.11.1。这个版本是在Scala 2.x系列中的一个稳定版,提供了许多改进和新特性。Scala 2.11.x系列的一个主要目标是提升与Java 7和8的兼容性,同时引入对...
Scala Maven 插件 scala-maven-plugin (以前是 maven-scala-plugin)用于在 Maven 中编译/测试/运行/记录 Scala 代码。类似插件 建造目前,您需要 Maven 3.x 和 JDK 8 来构建插件、创建站点并运行integration-test ...
scala-compiler.jar
"scala-intellij-bin-2016.3.9"是针对Scala语言的一个特定版本的IntelliJ IDEA插件,该版本为2016.3.9。这个插件是专门为Scala开发者设计的,旨在提高他们在IntelliJ IDEA中的开发体验。 Scala是一种多范式编程语言...
"Rock the JVM Scala Beginners" 提供了一个适合初学者的学习资源,帮助开发者掌握Scala的基础知识。在这个压缩包中,你可能会找到一系列的练习、示例代码和教程,让你逐步深入Scala的世界。 首先,Scala运行在Java...
在 Scala 中与 MongoDB 进行交互,通常我们会使用 `mongo-scala-driver`,而不是 `mongo-java-driver`,因为 Scala 驱动提供了更符合 Scala 语言特性的 API 设计。本示例将详细介绍如何使用 `mongo-scala-driver` ...
标题和描述中提到的"flink-1.19.0-bin-scala-2.12.tgz"和"flink-1.16.3-bin-scala-2.12.tgz"是Apache Flink的两个不同版本的二进制发行版。Flink是一个开源的流处理和批处理框架,它提供了低延迟、高吞吐量的数据...
scala-actors-2.10 jar包,可以解决 scala-actors-2.10以上版本带来的不兼容问题
scalajs-vue, Vue.js的Scala.js 绑定和示例应用程序 scalajs-vue用于 Vue.js的Scala.js-绑定和示例应用程序要作为图书馆使用,只要从https://jitpack.io/#fancellu/scalajs-vue 示例应用展示了使用 Scala.j
scala-js-ts-importer, Scala.js的打印机导入程序 从打字类型定义到 Scala.js的导入程序这里工具读取为 TypeScript 编写的类型定义文件,并将它们重写为可以使用 Scala.js的. scala 文件。过程不精确 100 %,因此...
flink-1.18.1-bin-scala-2.12 免费下载flink-1.18.1-bin-scala-2.12 免费下载flink-1.18.1-bin-scala-2.12 免费下载flink-1.18.1-bin-scala-2.12 免费下载flink-1.18.1-bin-scala-2.12 免费下载flink-1.18.1-bin-...
flink-1.9.1-bin-scala_2.11.tgz flink-1.9.1-bin-scala_2.11.tgz flink-1.9.1-bin-scala_2.11.tgz flink-1.9.1-bin-scala_2.11.tgz
赠送jar包:scala-parser-combinators_2.11-1.0.4.jar; 赠送原API文档:scala-parser-combinators_2.11-1.0.4-javadoc.jar; 赠送源代码:scala-parser-combinators_2.11-1.0.4-sources.jar; 赠送Maven依赖信息...
这个压缩包 "flink-1.12.7-bin-scala_2.12.tgz" 包含了 Flink 1.12.7 的二进制版本,特别针对使用 Scala 2.12 的开发环境进行了优化。 1. **Flink 的核心特性** - **流处理**:Flink 提供了一种无界限数据的概念,...
"scala-intellij-bin-2023.1.15.zip" 是一个包含IntelliJ IDEA针对Scala开发的特定版本的二进制发行包。 这个压缩包很可能包含了以下内容: 1. **IntelliJ IDEA安装程序**:这是主应用程序,允许用户在本地计算机...